security update for views

This commit is contained in:
Bachir Soussi Chiadmi 2018-04-20 23:59:18 +02:00
parent 57376251fa
commit 85772b4ca7
398 changed files with 11239 additions and 6207 deletions

View File

@ -1,19 +1,50 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Recommended
INTRODUCTION
------------
Welcome to Views 3. Please see the advanced help for more information. Welcome to Views 3. Please see the advanced help for more information.
If you're having trouble installing this module, please ensure that your If you're having trouble installing this module, please ensure that your tar
tar program is not flattening the directory tree, truncating filenames program is not flattening the directory tree, truncating filenames or losing
or losing files. files.
Installing Views:
Place the entirety of this directory in sites/all/modules/views REQUIREMENTS
You must also install the CTools module (http://www.drupal.org/project/ctools) to use Views. ------------
Navigate to administer >> build >> modules. Enable Views and Views UI. This module requires the following modules:
If you're new to Views, try the Simple Views module which can create some * Chaos tool suite (ctools) (https://drupal.org/project/ctools)
often used Views for you, this might save you some time.
Here you can find many modules extending the functionality of Views:
http://drupal.org/taxonomy/term/89 INSTALLATION
------------
Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-7 for further
information.
Navigate to administer >> modules. Enable Views and Views UI.
RECOMMENDED
-----------
* SimpleViews (https://www.drupal.org/project/simpleviews):
If you're new to Views, try the Simple Views which can create some often used
Views for you, this might save you some time.
* Advanced help (https://www.drupal.org/project/advanced_help):
If you enable the advanced help, Views will provide more and better help.
* Here you can find many modules extending the functionality of Views:
http://drupal.org/taxonomy/term/89

View File

@ -3,7 +3,7 @@
* in the Bartik theme. * in the Bartik theme.
*/ */
/* @group Lists */ /* @group Lists */
.views-display-top .secondary .action-list { .views-display-top .secondary .action-list {
padding-right: 0; padding-right: 0;

View File

@ -42,7 +42,7 @@
} }
.views-displays .secondary .open > a:hover { .views-displays .secondary .open > a:hover {
color: #0071B3; color: #0071b3;
} }
.views-displays .secondary input.form-submit { .views-displays .secondary input.form-submit {
@ -57,7 +57,7 @@
*/ */
.views-filterable-options .even .form-type-checkbox { .views-filterable-options .even .form-type-checkbox {
background-color: #F9F9F9; background-color: #f9f9f9;
} }
.views-ui-dialog .ui-dialog-titlebar-close, .views-ui-dialog .ui-dialog-titlebar-close,
@ -83,29 +83,28 @@
/* @group Buttons */ /* @group Buttons */
.ctools-button-processed { .ctools-button-processed {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
-moz-border-radius: 5px; -moz-border-radius: 5px;
-webkit-border-radius: 5px; -webkit-border-radius: 5px;
border-radius: 5px; border-radius: 5px;
@ -114,29 +113,28 @@
} }
.ctools-button-processed:hover { .ctools-button-processed:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f1f1f1 100%
#f1f1f1 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(241, 241, 241, 1.0))
color-stop(1.0, rgba(241, 241, 241, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%);
} }
.ctools-button-processed li a, .ctools-button-processed li a,
@ -150,29 +148,28 @@
} }
.ctools-dropbutton-processed.open:hover { .ctools-dropbutton-processed.open:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
} }
.ctools-dropbutton-processed.open { .ctools-dropbutton-processed.open {
@ -220,12 +217,12 @@
} }
.views-ui-display-tab-actions .ctools-button input { .views-ui-display-tab-actions .ctools-button input {
color: #0071B3; color: #0071b3;
} }
.views-ui-display-tab-actions .ctools-button input:hover, .views-ui-display-tab-actions .ctools-button input:hover,
.views-ui-display-tab-actions .ctools-button input:focus { .views-ui-display-tab-actions .ctools-button input:focus {
color: #018FE2; color: #018fe2;
} }
/* @end */ /* @end */

View File

@ -117,12 +117,12 @@
* *
* The tabs that switch between sections * The tabs that switch between sections
*/ */
.views-displays .secondary { .views-displays .secondary {
border-bottom: 0 none; border-bottom: 0 none;
margin: 0; margin: 0;
overflow: visible; overflow: visible;
padding: 0; padding: 0;
} }
.views-displays .secondary > li { .views-displays .secondary > li {
border-right: 0 none; border-right: 0 none;

View File

@ -10,7 +10,7 @@
} }
.ctools-dropbutton .ctools-link { .ctools-dropbutton .ctools-link {
border-right: 1px solid #ffffff; border-right: 1px solid #fff;
} }
.ctools-dropbutton li { .ctools-dropbutton li {

View File

@ -1,8 +1,8 @@
/* @group Buttons */ /* @group Buttons */
.ctools-button-processed { .ctools-button-processed {
background-color: #ffffff; background-color: #fff;
border-color: #cccccc; border-color: #ccc;
font-size: 11px; font-size: 11px;
padding-bottom: 2px; padding-bottom: 2px;
padding-top: 2px; padding-top: 2px;
@ -46,7 +46,7 @@
} }
.ctools-dropbutton-processed.open:hover { .ctools-dropbutton-processed.open:hover {
border-color: #D0D0D0; border-color: #d0d0d0;
} }
.ctools-dropbutton-processed.open { .ctools-dropbutton-processed.open {
@ -54,11 +54,11 @@
} }
.ctools-dropbutton-processed .ctools-link { .ctools-dropbutton-processed .ctools-link {
border-left: 1px solid #ffffff; border-left: 1px solid #fff;
} }
.ctools-dropbutton-processed.open .ctools-content { .ctools-dropbutton-processed.open .ctools-content {
padding-bottom: 4px; padding-bottom: 4px;
} }
.ctools-dropbutton-processed li a, .ctools-dropbutton-processed li a,
@ -132,7 +132,7 @@
.ctools-toggle.ctools-toggle-collapsed { .ctools-toggle.ctools-toggle-collapsed {
border-bottom-color: transparent; border-bottom-color: transparent;
border-left: 4px solid; border-left: 4px solid;
border-right-color: transparent; border-right-color: transparent;
border-top-color: transparent; border-top-color: transparent;
border-width: 5px 0 5px 5px; border-width: 5px 0 5px 5px;
@ -158,7 +158,7 @@
} }
.views-display-settings .ctools-toggle { .views-display-settings .ctools-toggle {
color: #000000; color: #000;
} }
.views-display-column > .ctools-toggle { .views-display-column > .ctools-toggle {
@ -173,7 +173,7 @@
} }
.views-display-column > .ctools-collapsible-handle { .views-display-column > .ctools-collapsible-handle {
border-color: #F3F3F3; border-color: #f3f3f3;
border-style: solid; border-style: solid;
border-width: 1px 1px 0; border-width: 1px 1px 0;
font-size: 13px; font-size: 13px;
@ -225,7 +225,7 @@ h2.ctools-collapsible-handle {
/* @group Jump list */ /* @group Jump list */
#views-live-preview .ctools-jump-menu-select{ #views-live-preview .ctools-jump-menu-select {
max-width: 450px; max-width: 450px;
} }

View File

@ -3,11 +3,11 @@
* in the Garland theme. * in the Garland theme.
*/ */
/* @group Lists */ /* @group Lists */
.views-displays .secondary .action-list { .views-displays .secondary .action-list {
left: auto; left: auto;
right: 1px; right: 1px;
} }
/* @end */ /* @end */

View File

@ -54,7 +54,7 @@
.views-displays .secondary .open > a:hover { .views-displays .secondary .open > a:hover {
border-color: #e9e9e9 #e9e9e9 #f1f1f1 #e9e9e9; border-color: #e9e9e9 #e9e9e9 #f1f1f1 #e9e9e9;
border-width: 1px 1px 1px 1px; border-width: 1px 1px 1px 1px;
color: #0071B3; color: #0071b3;
} }
.views-displays .secondary input.form-submit { .views-displays .secondary input.form-submit {
@ -84,7 +84,7 @@
} }
.views-filterable-options .even .form-type-checkbox { .views-filterable-options .even .form-type-checkbox {
background-color: #F9F9F9; background-color: #f9f9f9;
} }
.views-ui-dialog .ui-dialog-titlebar-close, .views-ui-dialog .ui-dialog-titlebar-close,
@ -101,29 +101,28 @@
/* @group Buttons */ /* @group Buttons */
.ctools-button-processed { .ctools-button-processed {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
-moz-border-radius: 5px; -moz-border-radius: 5px;
-webkit-border-radius: 5px; -webkit-border-radius: 5px;
border-radius: 5px; border-radius: 5px;
@ -132,29 +131,28 @@
} }
.ctools-button-processed:hover { .ctools-button-processed:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f1f1f1 100%
#f1f1f1 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(241, 241, 241, 1.0))
color-stop(1.0, rgba(241, 241, 241, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%);
} }
.ctools-button-processed ol li, .ctools-button-processed ol li,
@ -172,29 +170,28 @@
} }
.ctools-dropbutton-processed.open:hover { .ctools-dropbutton-processed.open:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
} }
.ctools-dropbutton-processed.open { .ctools-dropbutton-processed.open {
@ -249,13 +246,13 @@
} }
.views-ui-display-tab-actions .ctools-button input { .views-ui-display-tab-actions .ctools-button input {
color: #027AC6; color: #027ac6;
font-size: 12px; font-size: 12px;
} }
.views-ui-display-tab-actions .ctools-button input:hover, .views-ui-display-tab-actions .ctools-button input:hover,
.views-ui-display-tab-actions .ctools-button input:focus { .views-ui-display-tab-actions .ctools-button input:focus {
color: #0062A0; color: #0062a0;
} }
/* @end */ /* @end */

View File

@ -213,14 +213,14 @@ fieldset.fieldset-no-legend {
/* Override for input elements that are themed like ctools-buttons */ /* Override for input elements that are themed like ctools-buttons */
.ctools-button-processed input.form-submit:hover { .ctools-button-processed input.form-submit:hover {
background-image: none; background-image: none;
color: #0074BD; color: #0074bd;
text-shadow: none; text-shadow: none;
} }
.ctools-button-processed input.form-submit:active { .ctools-button-processed input.form-submit:active {
background: none; background: none;
border: medium none; border: medium none;
color: #0074BD; color: #0074bd;
text-shadow: none; text-shadow: none;
} }
@ -238,7 +238,7 @@ table th {
/* @group Attachment details */ /* @group Attachment details */
#edit-display-settings-title { #edit-display-settings-title {
color: #008BCB; color: #008bcb;
} }
/* @end */ /* @end */
@ -249,11 +249,11 @@ table th {
*/ */
.views-displays .secondary { .views-displays .secondary {
text-align: left; /* LTR */ text-align: left; /* LTR */
} }
.views-displays .secondary > li:first-child { .views-displays .secondary > li:first-child {
padding-left: 0; padding-left: 0;
} }
.views-admin .icon.add { .views-admin .icon.add {
@ -265,7 +265,7 @@ table th {
-moz-border-radius: 7px; -moz-border-radius: 7px;
-webkit-border-radius: 7px; -webkit-border-radius: 7px;
border-radius: 7px; border-radius: 7px;
color: #008BCB; color: #008bcb;
} }
.views-displays .secondary a:hover > .icon.add { .views-displays .secondary a:hover > .icon.add {
@ -280,7 +280,7 @@ table th {
.views-displays .secondary .open > a:hover { .views-displays .secondary .open > a:hover {
background-color: #f1f1f1; background-color: #f1f1f1;
color: #008BCB; color: #008bcb;
} }
.views-displays .secondary .action-list li:first-child { .views-displays .secondary .action-list li:first-child {
@ -299,7 +299,7 @@ table th {
-moz-border-radius: 0; -moz-border-radius: 0;
-webkit-border-radius: 0; -webkit-border-radius: 0;
border-radius: 0; border-radius: 0;
color: #008BCB; color: #008bcb;
} }
/* @end */ /* @end */
@ -349,11 +349,11 @@ table th {
} }
#views-ui-rearrange-filter-form tr.drag td { #views-ui-rearrange-filter-form tr.drag td {
background-color: #FFEE77 !important; background-color: #ffee77 !important;
} }
#views-ui-rearrange-filter-form tr.drag-previous td { #views-ui-rearrange-filter-form tr.drag-previous td {
background-color: #FFFFBB !important; background-color: #ffffbb !important;
} }
/* @end */ /* @end */
@ -402,7 +402,7 @@ table th {
-moz-box-shadow: none; -moz-box-shadow: none;
-webkit-box-shadow: none; -webkit-box-shadow: none;
box-shadow: none; box-shadow: none;
border-color: #cccccc; border-color: #ccc;
right: -27px; right: -27px;
top: -1px; top: -1px;
} }
@ -429,84 +429,81 @@ table th {
/* @group Buttons */ /* @group Buttons */
.ctools-button-processed { .ctools-button-processed {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
-moz-border-radius: 11px 11px 11px 11px; -moz-border-radius: 11px 11px 11px 11px;
-webkit-border-radius: 11px 11px 11px 11px; -webkit-border-radius: 11px 11px 11px 11px;
border-radius: 11px 11px 11px 11px; border-radius: 11px 11px 11px 11px;
} }
.ctools-button-processed:hover { .ctools-button-processed:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f1f1f1 100%
#f1f1f1 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(241, 241, 241, 1.0))
color-stop(1.0, rgba(241, 241, 241, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f1f1f1 100%
#ffffff 0px, );
#f1f1f1 100%);
} }
.ctools-dropbutton-processed.open:hover { .ctools-dropbutton-processed.open:hover {
background-image: background-image: -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #f9f9f9 100%
#f9f9f9 100%); );
background-image: background-image: -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(249, 249, 249, 1.0))
color-stop(1.0, rgba(249, 249, 249, 1.0)) );
); background-image: -webkit-linear-gradient(
background-image: -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%); background-image: linear-gradient(
background-image: -90deg,
linear-gradient( #fff 0px,
-90deg, #f9f9f9 100%
#ffffff 0px, );
#f9f9f9 100%);
} }
.ctools-dropbutton-processed.open { .ctools-dropbutton-processed.open {
@ -528,7 +525,7 @@ table th {
} }
.views-display-settings .ctools-toggle { .views-display-settings .ctools-toggle {
color: #008BCB; color: #008bcb;
} }
.views-display-column > .ctools-toggle { .views-display-column > .ctools-toggle {
@ -540,11 +537,11 @@ table th {
} }
.views-display-column > .ctools-collapsible-handle { .views-display-column > .ctools-collapsible-handle {
color: #008BCB; color: #008bcb;
} }
.views-ui-display-tab-actions .ctools-button-processed input { .views-ui-display-tab-actions .ctools-button-processed input {
color: #0074BD; color: #0074bd;
} }
/* @end */ /* @end */

View File

@ -39,35 +39,34 @@
.views-admin .icon, .views-admin .icon,
.views-admin .icon-text { .views-admin .icon-text {
background-attachment: scroll; background-attachment: scroll;
background-image: url("../images/sprites.png"); background-image: url('../images/sprites.png');
background-position: left top; /* LTR */ background-position: left top; /* LTR */
background-repeat: no-repeat; background-repeat: no-repeat;
} }
.views-admin a.icon { .views-admin a.icon {
background-image: background-image: url('../images/sprites.png'),
url("../images/sprites.png"), -moz-linear-gradient(
-moz-linear-gradient( -90deg,
-90deg, #fff 0px,
#ffffff 0px, #e8e8e8 100%
#e8e8e8 100%); );
background-image: background-image: url('../images/sprites.png'),
url("../images/sprites.png"), -webkit-gradient(
-webkit-gradient( linear,
linear, left top,
left top, left bottom,
left bottom, color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(0.0, rgba(255, 255, 255, 1.0)), color-stop(1.0, rgba(232, 232, 232, 1.0))
color-stop(1.0, rgba(232, 232, 232, 1.0)) );
); background-image: url('../images/sprites.png'),
background-image: -webkit-linear-gradient(
url("../images/sprites.png"), -90deg,
-webkit-linear-gradient( #fff 0px,
-90deg, #e8e8e8 100%
#ffffff 0px, );
#e8e8e8 100%);
background-repeat: no-repeat, repeat-y; background-repeat: no-repeat, repeat-y;
border: 1px solid #dddddd; border: 1px solid #ddd;
-moz-border-radius: 4px; -moz-border-radius: 4px;
-webkit-border-radius: 4px; -webkit-border-radius: 4px;
border-radius: 4px; border-radius: 4px;
@ -206,7 +205,7 @@ input.form-radio {
/* Hide 'remove' checkboxes. */ /* Hide 'remove' checkboxes. */
.views-remove-checkbox { .views-remove-checkbox {
display: none; display: none;
} }
/* sizes the labels of checkboxes and radio button to the height of the text */ /* sizes the labels of checkboxes and radio button to the height of the text */
@ -406,13 +405,13 @@ td.group-title {
/* @group Attachments */ /* @group Attachments */
.views-displays { .views-displays {
border: 1px solid #CCC; border: 1px solid #ccc;
padding-bottom: 36px; padding-bottom: 36px;
} }
.views-display-top { .views-display-top {
background-color: #F9F9F9; background-color: #f9f9f9;
border-bottom: 1px solid #CCCCCC; border-bottom: 1px solid #ccc;
padding: 8px 8px 8px; /* LTR */ padding: 8px 8px 8px; /* LTR */
position: relative; position: relative;
} }
@ -453,7 +452,7 @@ ul#views-display-menu-tabs li {
margin-bottom: 5px; margin-bottom: 5px;
} }
ul#views-display-menu-tabs li.add ul.action-list li{ ul#views-display-menu-tabs li.add ul.action-list li {
margin: 0; margin: 0;
} }
@ -470,7 +469,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
*/ */
.views-displays ul.secondary li.active a.active.error, .views-displays ul.secondary li.active a.active.error,
.views-displays .secondary a.error { .views-displays .secondary a.error {
border: 2px solid #ED541D; border: 2px solid #ed541d;
padding: 1px 6px; padding: 1px 6px;
} }
@ -480,8 +479,8 @@ ul#views-display-menu-tabs li.add ul.action-list li{
.views-displays .secondary a:hover, .views-displays .secondary a:hover,
.views-displays .secondary .active a { .views-displays .secondary .active a {
background-color: #666666; background-color: #666;
color: #ffffff; color: #fff;
border-bottom-width: 1px; border-bottom-width: 1px;
} }
@ -523,7 +522,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
.views-displays .secondary .action-list li:hover { .views-displays .secondary .action-list li:hover {
background-color: #dddddd; background-color: #ddd;
} }
/* @end */ /* @end */
@ -556,10 +555,10 @@ ul#views-display-menu-tabs li.add ul.action-list li{
*/ */
.views-display-column + .views-display-column { .views-display-column + .views-display-column {
margin-top: 0; margin-top: 0;
} }
/* @end */ /* @end */
/* @group Auto preview /* @group Auto preview
* *
@ -683,7 +682,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
*/ */
.views-ui-display-tab-bucket .views-display-setting { .views-ui-display-tab-bucket .views-display-setting {
color: #666666; color: #666;
font-size: 12px; font-size: 12px;
padding-bottom: 2px; padding-bottom: 2px;
} }
@ -753,8 +752,8 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
.views-ui-dialog .ui-dialog-titlebar-close { .views-ui-dialog .ui-dialog-titlebar-close {
background: url("../images/close.png") no-repeat scroll 6px 3px #F3F4EE; background: url('../images/close.png') no-repeat scroll 6px 3px #f3f4ee;
border-color: #aaaaaa; border-color: #aaa;
-moz-border-radius: 0 10px 12px 0; -moz-border-radius: 0 10px 12px 0;
-webkit-border-radius: 0 10px 12px 0; -webkit-border-radius: 0 10px 12px 0;
border-radius: 0 10px 12px 0; border-radius: 0 10px 12px 0;
@ -774,17 +773,17 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
.views-filterable-options .form-type-checkbox { .views-filterable-options .form-type-checkbox {
border: 1px solid #CCC; border: 1px solid #ccc;
padding: 5px 8px; padding: 5px 8px;
border-top: none; border-top: none;
} }
.views-filterable-options { .views-filterable-options {
border-top: 1px solid #CCC; border-top: 1px solid #ccc;
} }
.views-filterable-options .even .form-type-checkbox { .views-filterable-options .even .form-type-checkbox {
background-color: #F3F4EE; background-color: #f3f4ee;
} }
.filterable-option .form-item { .filterable-option .form-item {
@ -830,7 +829,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
.views-ui-dialog #views-ajax-title, .views-ui-dialog #views-ajax-title,
.views-ui-dialog .views-override { .views-ui-dialog .views-override {
background-color: #F3F4EE; background-color: #f3f4ee;
} }
.views-ui-dialog .views-override { .views-ui-dialog .views-override {
@ -862,7 +861,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
.views-ui-dialog .scroll { .views-ui-dialog .scroll {
border: 1px solid #CCC; border: 1px solid #ccc;
border-width: 1px 0; border-width: 1px 0;
padding: 8px 13px; padding: 8px 13px;
} }
@ -872,7 +871,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
.views-ui-dialog .form-buttons { .views-ui-dialog .form-buttons {
background-color: #F3F4EE; background-color: #f3f4ee;
padding: 8px 13px; padding: 8px 13px;
} }
.views-ui-dialog .form-buttons input { .views-ui-dialog .form-buttons input {
@ -888,7 +887,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
/* @todo Make this a class to be used anywhere there's node types? */ /* @todo Make this a class to be used anywhere there's node types? */
.form-type-checkboxes #edit-options-value, .form-type-checkboxes #edit-options-value,
.form-type-checkboxes #edit-options-validate-options-node-types { .form-type-checkboxes #edit-options-validate-options-node-types {
border-color: #CCCCCC; border-color: #ccc;
border-style: solid; border-style: solid;
border-width: 1px; border-width: 1px;
max-height: 210px; max-height: 210px;
@ -907,25 +906,25 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
#views-ui-rearrange-filter-form tr td[rowspan] { #views-ui-rearrange-filter-form tr td[rowspan] {
border-color: #CDCDCD; border-color: #cdcdcd;
border-style: solid; border-style: solid;
border-width: 0 1px 1px 1px; border-width: 0 1px 1px 1px;
} }
#views-ui-rearrange-filter-form tr[id^="views-row"] { #views-ui-rearrange-filter-form tr[id^="views-row"] {
border-right: 1px solid #CDCDCD; border-right: 1px solid #cdcdcd;
} }
#views-ui-rearrange-filter-form tr[id^="views-row"].even td { #views-ui-rearrange-filter-form tr[id^="views-row"].even td {
background-color: #F3F4ED; background-color: #f3f4ed;
} }
#views-ui-rearrange-filter-form .views-group-title { #views-ui-rearrange-filter-form .views-group-title {
border-top: 1px solid #CDCDCD; border-top: 1px solid #cdcdcd;
} }
#views-ui-rearrange-filter-form .group-empty { #views-ui-rearrange-filter-form .group-empty {
border-bottom: 1px solid #CDCDCD; border-bottom: 1px solid #cdcdcd;
} }
/* @end */ /* @end */
@ -945,8 +944,8 @@ ul#views-display-menu-tabs li.add ul.action-list li{
/* @group Live preview elements */ /* @group Live preview elements */
#views-preview-wrapper { #views-preview-wrapper {
border: 1px solid #CCC; border: 1px solid #ccc;
border-top: 2px solid #CCC; border-top: 2px solid #ccc;
padding-bottom: 12px; padding-bottom: 12px;
padding-top: 12px; padding-top: 12px;
} }
@ -979,7 +978,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
} }
#views-live-preview .preview-section { #views-live-preview .preview-section {
border: 1px dashed #DEDEDE; border: 1px dashed #dedede;
margin: 0 -5px; margin: 0 -5px;
padding: 3px 5px; padding: 3px 5px;
} }
@ -997,7 +996,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
.views-query-info table { .views-query-info table {
border-collapse: separate; border-collapse: separate;
border-color: #dddddd; border-color: #ddd;
border-spacing: 0; border-spacing: 0;
margin: 10px 0; margin: 10px 0;
} }
@ -1008,7 +1007,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
.views-query-info table th, .views-query-info table th,
.views-query-info table td { .views-query-info table td {
color: #666666; color: #666;
padding: 4px 10px; padding: 4px 10px;
} }
@ -1058,7 +1057,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{
.ajax-progress-throbber { .ajax-progress-throbber {
background-color: #232323; background-color: #232323;
background-image: url("../images/loading-small.gif"); background-image: url('../images/loading-small.gif');
background-position: center center; background-position: center center;
background-repeat: no-repeat; background-repeat: no-repeat;
-moz-border-radius: 7px; -moz-border-radius: 7px;

View File

@ -1,4 +1,3 @@
.views-exposed-form .views-exposed-widget { .views-exposed-form .views-exposed-widget {
float: right; /* RTL */ float: right; /* RTL */
padding: .5em 1em 0 0; /* RTL */ padding: .5em 1em 0 0; /* RTL */

View File

@ -2,14 +2,15 @@
/** /**
* @file * @file
* Drush integration of views. * Drush integration for Views.
* *
* drush cache-clear views - Clears the views specific caches. * Useful commands:
* views-revert - Drush command to revert views overridden in the system. * - drush cache-clear views - Clears the views specific caches.
* - views-revert - Drush command to revert views overridden in the system.
*/ */
/** /**
* Implement hook_drush_help(). * Implements hook_drush_help().
*/ */
function views_drush_help($section) { function views_drush_help($section) {
switch ($section) { switch ($section) {
@ -18,17 +19,20 @@ function views_drush_help($section) {
$help .= dt('If no view names are specified, you will be presented with a list of overridden views to choose from. '); $help .= dt('If no view names are specified, you will be presented with a list of overridden views to choose from. ');
$help .= dt('To revert all views, do not specify any view names, and choose the option "All" from the options presented.'); $help .= dt('To revert all views, do not specify any view names, and choose the option "All" from the options presented.');
return $help; return $help;
case 'drush:views-list': case 'drush:views-list':
return dt('Show a list of available views with information about them.'); return dt('Show a list of available views with information about them.');
case 'drush:views-enable': case 'drush:views-enable':
return dt('Enable the specified views. Follow the command with a space delimited list of view names'); return dt('Enable the specified views. Follow the command with a space delimited list of view names');
case 'drush:views-disable': case 'drush:views-disable':
return dt('Disable the specified views. Follow the command with a space delimited list of view names'); return dt('Disable the specified views. Follow the command with a space delimited list of view names');
} }
} }
/** /**
* Implement hook_drush_command(). * Implements hook_drush_command().
*/ */
function views_drush_command() { function views_drush_command() {
$items = array(); $items = array();
@ -70,7 +74,7 @@ function views_drush_command() {
'tags' => 'A comma-separated list of views tags by which to filter the results.', 'tags' => 'A comma-separated list of views tags by which to filter the results.',
'status' => 'Status of the views by which to filter the results. Choices: enabled, disabled.', 'status' => 'Status of the views by which to filter the results. Choices: enabled, disabled.',
'type' => 'Type of the views by which to filter the results. Choices: normal, default or overridden.', 'type' => 'Type of the views by which to filter the results. Choices: normal, default or overridden.',
), ),
'examples' => array( 'examples' => array(
'drush vl' => 'Show a list of all available views.', 'drush vl' => 'Show a list of all available views.',
'drush vl --name=blog' => 'Show a list of views which names contain "blog".', 'drush vl --name=blog' => 'Show a list of views which names contain "blog".',
@ -143,10 +147,10 @@ function views_revert_views() {
// If the user specified a list of views on the CLI, revert those. // If the user specified a list of views on the CLI, revert those.
elseif (!empty($viewnames)) { elseif (!empty($viewnames)) {
foreach ($viewnames as $key => $viewname) { foreach ($viewnames as $key => $viewname) {
$is_overridden = key_exists($viewname, $overridden); $is_overridden = array_key_exists($viewname, $overridden);
// Check if the provided view name is in the system // Check if the provided view name is in the system.
if ($viewname && !key_exists($viewname, $views)) { if ($viewname && !array_key_exists($viewname, $views)) {
drush_set_error(dt("'@viewname' view is not present in the system.", array('@viewname' => $viewname))); drush_set_error(dt("'@viewname' view is not present in the system.", array('@viewname' => $viewname)));
} }
// Check if the provided view is overridden. // Check if the provided view is overridden.
@ -158,7 +162,7 @@ function views_revert_views() {
views_revert_view($views[$viewname]); views_revert_view($views[$viewname]);
$i++; $i++;
} }
// We should never get here but well... // We should never get here but well.
else { else {
drush_set_error(dt( drush_set_error(dt(
"The view specified '@viewname' is not provided in code, and thus cannot be reverted.", "The view specified '@viewname' is not provided in code, and thus cannot be reverted.",
@ -168,19 +172,20 @@ function views_revert_views() {
} }
} }
// The user neither selected the "--all" option, nor provided a list of views to revert. // The user neither selected the "--all" option, nor provided a list of views
// Prompt the user. // to revert. Prompt the user.
else { else {
// list of choices for the user // List of choices for the user.
$overridden['all'] = dt('Revert all overridden views'); // add a choice at the end $overridden['all'] = dt('Revert all overridden views');
$choice = drush_choice($overridden, 'Enter a number to choose which view to revert.', '!key'); // prompt the user // 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) { if ($choice !== FALSE) {
// revert all views option // Revert all views option.
if ($choice == 'all') { if ($choice == 'all') {
$i = views_revert_allviews($views); $i = views_revert_allviews($views);
} }
// else the user specified a single view // Else the user specified a single view.
else { else {
views_revert_view($views[$choice]); views_revert_view($views[$choice]);
$i++; $i++;
@ -189,7 +194,7 @@ function views_revert_views() {
} }
// final results output // Final results output.
if ($i == 0) { if ($i == 0) {
drush_log(dt('No views were reverted.'), 'ok'); drush_log(dt('No views were reverted.'), 'ok');
} }
@ -199,9 +204,10 @@ function views_revert_views() {
} }
/** /**
* Reverts all views * Reverts all views.
* @param $views *
* All views in the system as provided by views_get_all_views(). * @param array $views
* All views in the system as provided by views_get_all_views().
*/ */
function views_revert_allviews($views) { function views_revert_allviews($views) {
$i = 0; $i = 0;
@ -219,15 +225,17 @@ function views_revert_allviews($views) {
} }
/** /**
* Revert a specified view * 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() * Checks on wether or not the view is overridden is handled in
* We perform a check here anyway in case someone somehow calls this function on their own... * views_revert_views_revert(). We perform a check here anyway in case someone
* somehow calls this function on their own...
*
* @param object $view
* The view object to be reverted.
*/ */
function views_revert_view($view) { function views_revert_view($view) {
// check anyway just in case // Check anyway just in case.
if ($view->type == t('Overridden')) { if ($view->type == t('Overridden')) {
// Revert the view. // Revert the view.
$view->delete(); $view->delete();
@ -269,7 +277,7 @@ function views_development_settings() {
* Callback function for views-list command. * Callback function for views-list command.
*/ */
function drush_views_list() { function drush_views_list() {
// Initialize stuf // Initialize stuff.
$rows = array(); $rows = array();
$disabled_views = array(); $disabled_views = array();
$enabled_views = array(); $enabled_views = array();
@ -281,19 +289,18 @@ function drush_views_list() {
$views = views_get_all_views(); $views = views_get_all_views();
// get the --name option // Get the --name option.
// TODO : take into account the case off a comma-separated list of names // @todo Take into account the case off a comma-separated list of names.
$name = drush_get_option_list('name'); $name = drush_get_option_list('name');
$with_name = !empty($name) ? TRUE : FALSE; $with_name = !empty($name) ? TRUE : FALSE;
// get the --tags option // Get the --tags option.
$tags = drush_get_option_list('tags'); $tags = drush_get_option_list('tags');
$with_tags = !empty($tags) ? TRUE : FALSE; $with_tags = !empty($tags) ? TRUE : FALSE;
// get the --status option // Get the --status option. Store user input appart to reuse it after.
// store user input appart to reuse it after
$status_opt = drush_get_option_list('status'); $status_opt = drush_get_option_list('status');
// use the same logic than $view->disabled // Use the same logic than $view->disabled.
if (in_array('disabled', $status_opt)) { if (in_array('disabled', $status_opt)) {
$status = TRUE; $status = TRUE;
$with_status = TRUE; $with_status = TRUE;
@ -304,19 +311,19 @@ function drush_views_list() {
} }
else { else {
$status = NULL; $status = NULL;
// wrong or empty --status option // Wrong or empty --status option.
$with_status = FALSE; $with_status = FALSE;
} }
// get the --type option // Get the --type option.
$type = drush_get_option_list('type'); $type = drush_get_option_list('type');
// use the same logic than $view->type // Use the same logic than $view->type.
$with_type = FALSE; $with_type = FALSE;
if (in_array('normal', $type) || in_array('default', $type)|| in_array('overridden', $type)) { if (in_array('normal', $type) || in_array('default', $type)|| in_array('overridden', $type)) {
$with_type = TRUE; $with_type = TRUE;
} }
// set the table headers // Set the table headers.
$header = array( $header = array(
dt('Machine name'), dt('Machine name'),
dt('Description'), dt('Description'),
@ -325,10 +332,10 @@ function drush_views_list() {
dt('Tag'), dt('Tag'),
); );
// setup a row for each view // Setup a row for each view.
foreach($views as $id => $view){ foreach ($views as $id => $view) {
// if options were specified, check that first // If options were specified, check that first mismatch push the loop to
// mismatch push the loop to the next view // the next view.
if ($with_tags && !in_array($view->tag, $tags)) { if ($with_tags && !in_array($view->tag, $tags)) {
continue; continue;
} }
@ -343,25 +350,25 @@ function drush_views_list() {
} }
$row = array(); $row = array();
// each row entry should be in the same order as the header // Each row entry should be in the same order as the header.
$row[] = $view->name; $row[] = $view->name;
$row[] = $view->description; $row[] = $view->description;
$row[] = $view->type; $row[] = $view->type;
$row[] = $view->disabled ? dt('Disabled') : dt('Enabled'); $row[] = $view->disabled ? dt('Disabled') : dt('Enabled');
$row[] = $view->tag; $row[] = $view->tag;
// place the row in the appropiate array, // Place the row in the appropiate array so we can have disabled views at
// so we can have disabled views at the bottom // the bottom.
if($view->disabled) { if ($view->disabled) {
$disabled_views[] = $row; $disabled_views[] = $row;
} }
else{ else {
$enabled_views[] = $row; $enabled_views[] = $row;
} }
unset($row); unset($row);
// gather some statistics // Gather some statistics.
switch($view->type) { switch ($view->type) {
case dt('Normal'): case dt('Normal'):
$indb++; $indb++;
break; break;
@ -379,11 +386,11 @@ function drush_views_list() {
$disabled = count($disabled_views); $disabled = count($disabled_views);
// sort alphabeticaly // Sort alphabeticaly.
asort($disabled_views); asort($disabled_views);
asort($enabled_views); asort($enabled_views);
// if options were used // If options were used.
$summary = ""; $summary = "";
if ($with_name || $with_tags || $with_status || $with_type) { if ($with_name || $with_tags || $with_status || $with_type) {
$summary = "Views"; $summary = "Views";
@ -412,23 +419,26 @@ function drush_views_list() {
drush_print($summary . "\n"); drush_print($summary . "\n");
} }
// print all rows as a table // Print all rows as a table.
if ($total > 0) { if ($total > 0) {
$rows = array_merge($enabled_views, $disabled_views); $rows = array_merge($enabled_views, $disabled_views);
// put the headers as first row // Put the headers as first row.
array_unshift($rows, $header); array_unshift($rows, $header);
drush_print_table($rows, TRUE); drush_print_table($rows, TRUE);
} }
// print the statistics messages // Print the statistics messages.
drush_print(dt("A total of @total views were found in this Drupal installation:", array('@total' => $total))); drush_print(dt("A total of @total views were found in this Drupal installation:", array('@total' => $total)));
drush_print(dt(" @indb views reside only in the database", array('@indb' => $indb ))); drush_print(dt(" @indb views reside only in the database", array('@indb' => $indb)));
drush_print(dt(" @over views are overridden", array('@over' => $overridden))); drush_print(dt(" @over views are overridden", array('@over' => $overridden)));
drush_print(dt(" @incode views are in their default state", array('@incode' => $incode))); drush_print(dt(" @incode views are in their default state", array('@incode' => $incode)));
drush_print(dt(" @dis views are disabled\n", array('@dis' => $disabled))); drush_print(dt(" @dis views are disabled\n", array('@dis' => $disabled)));
} }
/**
* Analyze all installed views.
*/
function drush_views_analyze() { function drush_views_analyze() {
views_include('analyze'); views_include('analyze');
$messages_count = 0; $messages_count = 0;
@ -440,7 +450,7 @@ function drush_views_analyze() {
drush_print($view_name); drush_print($view_name);
foreach ($messages as $message) { foreach ($messages as $message) {
$messages_count++; $messages_count++;
drush_print($message['type'] .': '. $message['message'], 2); drush_print($message['type'] . ': ' . $message['message'], 2);
} }
} }
} }
@ -448,7 +458,7 @@ function drush_views_analyze() {
} }
/** /**
* Enables views * Enables views.
*/ */
function drush_views_enable() { function drush_views_enable() {
$viewnames = _convert_csv_to_array(func_get_args()); $viewnames = _convert_csv_to_array(func_get_args());
@ -460,7 +470,7 @@ function drush_views_enable() {
} }
/** /**
* Disables views * Disables views.
*/ */
function drush_views_disable() { function drush_views_disable() {
$viewnames = _convert_csv_to_array(func_get_args()); $viewnames = _convert_csv_to_array(func_get_args());
@ -472,9 +482,12 @@ function drush_views_disable() {
} }
/** /**
* Helper function to enable / disable views * Helper function to enable / disable views.
* @param $viewnames: array of viewnames to process *
* @param $status: TRUE to disable or FALSE to enable the view * @param array $viewnames
* Names of the views to process.
* @param bool $status
* TRUE to disable or FALSE to enable the view.
*/ */
function _views_drush_changestatus($viewnames = array(), $status = NULL) { function _views_drush_changestatus($viewnames = array(), $status = NULL) {
if ($status !== NULL && !empty($viewnames)) { if ($status !== NULL && !empty($viewnames)) {
@ -492,7 +505,7 @@ function _views_drush_changestatus($viewnames = array(), $status = NULL) {
drush_set_error(dt("The view '!name' is already !processed", array('!name' => $viewname, '!processed' => $processed))); drush_set_error(dt("The view '!name' is already !processed", array('!name' => $viewname, '!processed' => $processed)));
} }
} }
// If we made changes to views status, save them and clear caches // If we made changes to views status, save them and clear caches.
if ($changed) { if ($changed) {
variable_set('views_defaults', $views_status); variable_set('views_defaults', $views_status);
views_invalidate_cache(); views_invalidate_cache();
@ -504,6 +517,9 @@ function _views_drush_changestatus($viewnames = array(), $status = NULL) {
/** /**
* Adds a cache clear option for views. * Adds a cache clear option for views.
*
* @param array $types
* The list of cache types that are available.
*/ */
function views_drush_cache_clear(&$types) { function views_drush_cache_clear(&$types) {
$types['views'] = 'views_invalidate_cache'; $types['views'] = 'views_invalidate_cache';

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Views area handlers. * Definition of views_handler_area and views_handler_area_broken.
*/ */
/** /**
@ -20,29 +20,31 @@
class views_handler_area extends views_handler { class views_handler_area extends views_handler {
/** /**
* Overrides views_handler::init(). * {@inheritdoc}
*
* Make sure that no result area handlers are set to be shown when the result
* is empty.
*/ */
function init(&$view, &$options) { public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
// Make sure that no result area handlers are set to be shown when the
// result is empty.
if ($this->handler_type == 'empty') { if ($this->handler_type == 'empty') {
$this->options['empty'] = TRUE; $this->options['empty'] = TRUE;
} }
} }
/** /**
* Get this field's label. * {@inheritdoc}
*/ */
function label() { public function label() {
if (!isset($this->options['label'])) { if (!isset($this->options['label'])) {
return $this->ui_name(); return $this->ui_name();
} }
return $this->options['label']; return $this->options['label'];
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : ''; $this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
@ -54,17 +56,17 @@ class views_handler_area extends views_handler {
} }
/** /**
* Provide extra data to the administration form * Provide extra data to the administration form.
*/ */
function admin_summary() { public function admin_summary() {
return $this->label(); return $this->label();
} }
/** /**
* Default options form that provides the label widget that all fields * Default options form that provides the label widget that all fields should
* should have. * have.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['label'] = array( $form['label'] = array(
'#type' => 'textfield', '#type' => 'textfield',
@ -83,23 +85,25 @@ class views_handler_area extends views_handler {
} }
/** /**
* Don't run a query * Don't run a query.
*/ */
function query() { } public function query() {
}
/** /**
* Render the area * Render the area.
*/ */
function render($empty = FALSE) { public function render($empty = FALSE) {
return ''; return '';
} }
/** /**
* Area handlers shouldn't have groupby. * Area handlers shouldn't have groupby.
*/ */
function use_group_by() { public function use_group_by() {
return FALSE; return FALSE;
} }
} }
/** /**
@ -108,14 +112,39 @@ class views_handler_area extends views_handler {
* @ingroup views_area_handlers * @ingroup views_area_handlers
*/ */
class views_handler_area_broken extends views_handler_area { class views_handler_area_broken extends views_handler_area {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query($group_by = FALSE) { /* No query to run */ } * {@inheritdoc}
function render($empty = FALSE) { return ''; } */
function options_form(&$form, &$form_state) { public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
return '';
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#prefix' => '<div class="form-item description">', '#prefix' => '<div class="form-item description">',
'#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.'), '#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.'),
@ -123,9 +152,12 @@ class views_handler_area_broken extends views_handler_area {
} }
/** /**
* Determine if the handler is considered 'broken' * {@inheritdoc}
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }
/** /**

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains views_handler_area_messages. * Definition of views_handler_area_messages.
*/ */
/** /**

View File

@ -12,7 +12,10 @@
*/ */
class views_handler_area_result extends views_handler_area { class views_handler_area_result extends views_handler_area {
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['content'] = array( $options['content'] = array(
@ -23,7 +26,10 @@ class views_handler_area_result extends views_handler_area {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$variables = array( $variables = array(
'items' => array( 'items' => array(
@ -47,11 +53,10 @@ class views_handler_area_result extends views_handler_area {
); );
} }
/** /**
* Find out the information to render. * Find out the information to render.
*/ */
function render($empty = FALSE) { public function render($empty = FALSE) {
// Must have options and does not work on summaries. // Must have options and does not work on summaries.
if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') { if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
return; return;
@ -61,7 +66,7 @@ class views_handler_area_result extends views_handler_area {
// Calculate the page totals. // Calculate the page totals.
$current_page = (int) $this->view->get_current_page() + 1; $current_page = (int) $this->view->get_current_page() + 1;
$per_page = (int) $this->view->get_items_per_page(); $per_page = (int) $this->view->get_items_per_page();
// @TODO: Maybe use a possible is views empty functionality. // @todo Maybe use a possible is views empty functionality.
// Not every view has total_rows set, use view->result instead. // Not every view has total_rows set, use view->result instead.
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result); $total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
$name = check_plain($this->view->human_name); $name = check_plain($this->view->human_name);
@ -81,7 +86,16 @@ class views_handler_area_result extends views_handler_area {
} }
$current_record_count = ($end - $start) + 1; $current_record_count = ($end - $start) + 1;
// Get the search information. // Get the search information.
$items = array('start', 'end', 'total', 'name', 'per_page', 'current_page', 'current_record_count', 'page_count'); $items = array(
'start',
'end',
'total',
'name',
'per_page',
'current_page',
'current_record_count',
'page_count',
);
$replacements = array(); $replacements = array();
foreach ($items as $item) { foreach ($items as $item) {
$replacements["@$item"] = ${$item}; $replacements["@$item"] = ${$item};
@ -92,4 +106,5 @@ class views_handler_area_result extends views_handler_area {
} }
return $output; return $output;
} }
} }

View File

@ -12,15 +12,30 @@
*/ */
class views_handler_area_text extends views_handler_area { class views_handler_area_text extends views_handler_area {
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['content'] = array('default' => '', 'translatable' => TRUE, 'format_key' => 'format'); $options['content'] = array(
$options['format'] = array('default' => NULL); 'default' => '',
$options['tokenize'] = array('default' => FALSE, 'bool' => TRUE); 'translatable' => TRUE,
'format_key' => 'format',
);
$options['format'] = array(
'default' => NULL,
);
$options['tokenize'] = array(
'default' => FALSE,
'bool' => TRUE,
);
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['content'] = array( $form['content'] = array(
@ -31,7 +46,7 @@ class views_handler_area_text extends views_handler_area {
'#wysiwyg' => FALSE, '#wysiwyg' => FALSE,
); );
// @TODO: Refactor token handling into a base class. // @todo Refactor token handling into a base class.
$form['tokenize'] = array( $form['tokenize'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Use replacement tokens from the first row'), '#title' => t('Use replacement tokens from the first row'),
@ -44,14 +59,17 @@ class views_handler_area_text extends views_handler_area {
$options[t('Fields')]["[$field]"] = $handler->ui_name(); $options[t('Fields')]["[$field]"] = $handler->ui_name();
} }
$count = 0; // This lets us prepare the key as we want it printed. $count = 0;
// This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { 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 title', array('@argument' => $handler->ui_name()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
} }
if (!empty($options)) { if (!empty($options)) {
$output = '<p>' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '</p>'); $output = '<p>'
. t("The following tokens are available. If you would like to have the characters '[' and ']' please use the html entity codes '%5B' or '%5D' or they will get replaced with empty space.")
. '</p>';
foreach (array_keys($options) as $type) { foreach (array_keys($options) as $type) {
if (!empty($options[$type])) { if (!empty($options[$type])) {
$items = array(); $items = array();
@ -61,7 +79,7 @@ class views_handler_area_text extends views_handler_area {
$output .= theme('item_list', $output .= theme('item_list',
array( array(
'items' => $items, 'items' => $items,
'type' => $type 'type' => $type,
)); ));
} }
} }
@ -82,13 +100,19 @@ class views_handler_area_text extends views_handler_area {
} }
} }
function options_submit(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_submit(&$form, &$form_state) {
$form_state['values']['options']['format'] = $form_state['values']['options']['content']['format']; $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
$form_state['values']['options']['content'] = $form_state['values']['options']['content']['value']; $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value'];
parent::options_submit($form, $form_state); parent::options_submit($form, $form_state);
} }
function render($empty = FALSE) { /**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
$format = isset($this->options['format']) ? $this->options['format'] : filter_default_format(); $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
if (!$empty || !empty($this->options['empty'])) { if (!$empty || !empty($this->options['empty'])) {
return $this->render_textarea($this->options['content'], $format); return $this->render_textarea($this->options['content'], $format);
@ -99,7 +123,7 @@ class views_handler_area_text extends views_handler_area {
/** /**
* Render a text area, using the proper format. * Render a text area, using the proper format.
*/ */
function render_textarea($value, $format) { public function render_textarea($value, $format) {
if ($value) { if ($value) {
if ($this->options['tokenize']) { if ($this->options['tokenize']) {
$value = $this->view->style_plugin->tokenize_value($value, 0); $value = $this->view->style_plugin->tokenize_value($value, 0);
@ -107,4 +131,5 @@ class views_handler_area_text extends views_handler_area {
return check_markup($value, $format, '', FALSE); return check_markup($value, $format, '', FALSE);
} }
} }
} }

View File

@ -12,13 +12,19 @@
*/ */
class views_handler_area_text_custom extends views_handler_area_text { class views_handler_area_text_custom extends views_handler_area_text {
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
unset($options['format']); unset($options['format']);
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Alter the form element, to be a regular text area. // Alter the form element, to be a regular text area.
@ -26,14 +32,20 @@ class views_handler_area_text_custom extends views_handler_area_text {
unset($form['content']['#format']); unset($form['content']['#format']);
unset($form['content']['#wysiwyg']); unset($form['content']['#wysiwyg']);
// @TODO: Use the token refactored base class. // @todo Use the token refactored base class.
} }
// Empty, so we don't inherit options_submit from the parent. /**
function options_submit(&$form, &$form_state) { * {@inheritdoc}
*/
public function options_submit(&$form, &$form_state) {
// Empty, so we don't inherit options_submit from the parent.
} }
function render($empty = FALSE) { /**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) { if (!$empty || !empty($this->options['empty'])) {
return $this->render_textarea_custom($this->options['content']); return $this->render_textarea_custom($this->options['content']);
} }
@ -43,8 +55,14 @@ class views_handler_area_text_custom extends views_handler_area_text {
/** /**
* Render a text area with filter_xss_admin. * Render a text area with filter_xss_admin.
*
* @param string $value
* The text area string to process.
*
* @return string
* The string after it has been sanitized, optionally tokenized too.
*/ */
function render_textarea_custom($value) { public function render_textarea_custom($value) {
if ($value) { if ($value) {
if ($this->options['tokenize']) { if ($this->options['tokenize']) {
$value = $this->view->style_plugin->tokenize_value($value, 0); $value = $this->view->style_plugin->tokenize_value($value, 0);

View File

@ -12,7 +12,10 @@
*/ */
class views_handler_area_view extends views_handler_area { class views_handler_area_view extends views_handler_area {
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['view_to_insert'] = array('default' => ''); $options['view_to_insert'] = array('default' => '');
@ -21,10 +24,9 @@ class views_handler_area_view extends views_handler_area {
} }
/** /**
* Default options form that provides the label widget that all fields * Default options form; provides the label widget all fields should have.
* should have.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$view_display = $this->view->name . ':' . $this->view->current_display; $view_display = $this->view->name . ':' . $this->view->current_display;
@ -48,9 +50,9 @@ class views_handler_area_view extends views_handler_area {
} }
/** /**
* Render the area * Render the area.
*/ */
function render($empty = FALSE) { public function render($empty = FALSE) {
if ($view = $this->loadView()) { if ($view = $this->loadView()) {
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
return $view->preview(NULL, $this->view->args); return $view->preview(NULL, $this->view->args);

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* @todo. * Definition of views_handler_argument.
*/ */
/** /**
@ -18,46 +18,59 @@
* *
* Definition terms for this handler: * Definition terms for this handler:
* - name field: The field to use for the name to use in the summary, which is * - name field: The field to use for the name to use in the summary, which is
* the displayed output. For example, for the node: nid argument, * the displayed output. For example, for the node: nid argument, the argument
* the argument itself is the nid, but node.title is displayed. * itself is the nid, but node.title is displayed.
* - name table: The table to use for the name, should it not be in the same * - name table: The table to use for the name, should it not be in the same
* table as the argument. * table as the argument.
* - empty field name: For arguments that can have no value, such as taxonomy * - empty field name: For arguments that can have no value, such as taxonomy
* which can have "no term", this is the string which * which can have "no term", this is the string which will be displayed for
* will be displayed for this lack of value. Be sure to use * this lack of value. Be sure to use t().
* t().
* - validate type: A little used string to allow an argument to restrict * - validate type: A little used string to allow an argument to restrict
* which validator is available to just one. Use the * which validator is available to just one. Use the validator ID. This
* validator ID. This probably should not be used at all, * probably should not be used at all, and may disappear or change.
* and may disappear or change.
* - numeric: If set to TRUE this field is numeric and will use %d instead of * - numeric: If set to TRUE this field is numeric and will use %d instead of
* %s in queries. * %s in queries.
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument extends views_handler { class views_handler_argument extends views_handler {
var $validator = NULL;
var $argument = NULL;
var $value = NULL;
/** /**
* The table to use for the name, should it not be in the same table as the argument. * @var object
*/
public $validator = NULL;
/**
* @var mixed
*/
public $argument = NULL;
/**
* @var mixed
*/
public $value = NULL;
/**
* The table to use for the name, if not the same table as the argument.
*
* @var string * @var string
*/ */
var $name_table; public $name_table;
/** /**
* The field to use for the name to use in the summary, which is * The field to use for the name to use in the summary.
* the displayed output. For example, for the node: nid argument, *
* the argument itself is the nid, but node.title is displayed. * Used as the displayed output. For example, for the node: nid argument, the
* argument itself is the nid, but node.title is displayed.
*
* @var string * @var string
*/ */
var $name_field; public $name_field;
/** /**
* Constructor * {@inheritdoc}
*/ */
function construct() { public function construct() {
parent::construct(); parent::construct();
if (!empty($this->definition['name field'])) { if (!empty($this->definition['name field'])) {
@ -68,7 +81,10 @@ class views_handler_argument extends views_handler {
} }
} }
function init(&$view, &$options) { /**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
// Compatibility: The new UI changed several settings. // Compatibility: The new UI changed several settings.
@ -132,31 +148,42 @@ class views_handler_argument extends views_handler {
/** /**
* Give an argument the opportunity to modify the breadcrumb, if it wants. * Give an argument the opportunity to modify the breadcrumb, if it wants.
* This only gets called on displays where a breadcrumb is actually used. *
* 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 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. * the path and the value being the already sanitized title of the path.
*/ */
function set_breadcrumb(&$breadcrumb) { } public function set_breadcrumb(&$breadcrumb) {
}
/** /**
* Determine if the argument can generate a breadcrumb * Determine if the argument can generate a breadcrumb
* *
* @return TRUE/FALSE * @return bool
*/ */
function uses_breadcrumb() { public function uses_breadcrumb() {
$info = $this->default_actions($this->options['default_action']); $info = $this->default_actions($this->options['default_action']);
return !empty($info['breadcrumb']); return !empty($info['breadcrumb']);
} }
function is_exception($arg = NULL) { /**
* {@inheritdoc}
*/
public function is_exception($arg = NULL) {
if (!isset($arg)) { if (!isset($arg)) {
$arg = isset($this->argument) ? $this->argument : NULL; $arg = isset($this->argument) ? $this->argument : NULL;
} }
return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg; return !empty($this->options['exception']['value']) && ($this->options['exception']['value'] === $arg);
} }
function exception_title() { /**
* Work out which title to use.
*
* @return string
* The title string to use.
*/
public function exception_title() {
// If title overriding is off for the exception, return the normal title. // If title overriding is off for the exception, return the normal title.
if (empty($this->options['exception']['title_enable'])) { if (empty($this->options['exception']['title_enable'])) {
return $this->get_title(); return $this->get_title();
@ -167,15 +194,18 @@ class views_handler_argument extends views_handler {
/** /**
* Determine if the argument needs a style plugin. * Determine if the argument needs a style plugin.
* *
* @return TRUE/FALSE * @return bool
*/ */
function needs_style_plugin() { public function needs_style_plugin() {
$info = $this->default_actions($this->options['default_action']); $info = $this->default_actions($this->options['default_action']);
$validate_info = $this->default_actions($this->options['validate']['fail']); $validate_info = $this->default_actions($this->options['validate']['fail']);
return !empty($info['style plugin']) || !empty($validate_info['style plugin']); return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['default_action'] = array('default' => 'ignore'); $options['default_action'] = array('default' => 'ignore');
@ -213,7 +243,10 @@ class views_handler_argument extends views_handler {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$argument_text = $this->view->display_handler->get_argument_text(); $argument_text = $this->view->display_handler->get_argument_text();
@ -380,8 +413,9 @@ class views_handler_argument extends views_handler {
'#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">', '#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#type' => 'item', '#type' => 'item',
// Even if the plugin has no options add the key to the form_state. // Even if the plugin has no options, add the key to the
'#input' => TRUE, // trick it into checking input to make #process run // form_state. Trick it into checking input to make #process run.
'#input' => TRUE,
'#dependency' => array( '#dependency' => array(
'edit-options-specify-validation' => array('1'), 'edit-options-specify-validation' => array('1'),
'edit-options-validate-type' => array($id), 'edit-options-validate-type' => array($id),
@ -411,7 +445,10 @@ class views_handler_argument extends views_handler {
); );
} }
function options_validate(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_validate(&$form, &$form_state) {
if (empty($form_state['values']['options'])) { if (empty($form_state['values']['options'])) {
return; return;
} }
@ -440,7 +477,10 @@ class views_handler_argument extends views_handler {
} }
function options_submit(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_submit(&$form, &$form_state) {
if (empty($form_state['values']['options'])) { if (empty($form_state['values']['options'])) {
return; return;
} }
@ -451,7 +491,8 @@ class views_handler_argument extends views_handler {
if ($plugin) { if ($plugin) {
$options = &$form_state['values']['options']['argument_default'][$default_id]; $options = &$form_state['values']['options']['argument_default'][$default_id];
$plugin->options_submit($form['argument_default'][$default_id], $form_state, $options); $plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
// Copy the now submitted options to their final resting place so they get saved. // Copy the now submitted options to their final resting place so they
// get saved.
$form_state['values']['options']['default_argument_options'] = $options; $form_state['values']['options']['default_argument_options'] = $options;
} }
@ -462,7 +503,8 @@ class views_handler_argument extends views_handler {
if ($plugin) { if ($plugin) {
$options = &$form_state['values']['options']['summary']['options'][$summary_id]; $options = &$form_state['values']['options']['summary']['options'][$summary_id];
$plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options); $plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options);
// Copy the now submitted options to their final resting place so they get saved. // Copy the now submitted options to their final resting place so they
// get saved.
$form_state['values']['options']['summary_options'] = $options; $form_state['values']['options']['summary_options'] = $options;
} }
} }
@ -472,7 +514,8 @@ class views_handler_argument extends views_handler {
if ($plugin) { if ($plugin) {
$options = &$form_state['values']['options']['validate']['options'][$validate_id]; $options = &$form_state['values']['options']['validate']['options'][$validate_id];
$plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options); $plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options);
// Copy the now submitted options to their final resting place so they get saved. // Copy the now submitted options to their final resting place so they
// get saved.
$form_state['values']['options']['validate_options'] = $options; $form_state['values']['options']['validate_options'] = $options;
} }
@ -489,42 +532,49 @@ class views_handler_argument extends views_handler {
* *
* Override this method to provide additional (or fewer) default behaviors. * Override this method to provide additional (or fewer) default behaviors.
*/ */
function default_actions($which = NULL) { public function default_actions($which = NULL) {
$defaults = array( $defaults = array(
'ignore' => array( 'ignore' => array(
'title' => t('Display all results for the specified field'), 'title' => t('Display all results for the specified field'),
'method' => 'default_ignore', 'method' => 'default_ignore',
'breadcrumb' => TRUE, // generate a breadcrumb to here // Generate a breadcrumb to here.
'breadcrumb' => TRUE,
), ),
'default' => array( 'default' => array(
'title' => t('Provide default value'), 'title' => t('Provide default value'),
'method' => 'default_default', 'method' => 'default_default',
'form method' => 'default_argument_form', 'form method' => 'default_argument_form',
'has default argument' => TRUE, 'has default argument' => TRUE,
'default only' => TRUE, // this can only be used for missing argument, not validation failure // This can only be used for missing argument, not validation failure.
'breadcrumb' => TRUE, // generate a breadcrumb to here 'default only' => TRUE,
// Generate a breadcrumb to here.
'breadcrumb' => TRUE,
), ),
'not found' => array( 'not found' => array(
'title' => t('Hide view'), 'title' => t('Hide view'),
'method' => 'default_not_found', 'method' => 'default_not_found',
'hard fail' => TRUE, // This is a hard fail condition // This is a hard fail condition.
'hard fail' => TRUE,
), ),
'summary' => array( 'summary' => array(
'title' => t('Display a summary'), 'title' => t('Display a summary'),
'method' => 'default_summary', 'method' => 'default_summary',
'form method' => 'default_summary_form', 'form method' => 'default_summary_form',
'style plugin' => TRUE, 'style plugin' => TRUE,
'breadcrumb' => TRUE, // generate a breadcrumb to here // Generate a breadcrumb to here.
'breadcrumb' => TRUE,
), ),
'empty' => array( 'empty' => array(
'title' => t('Display contents of "No results found"'), 'title' => t('Display contents of "No results found"'),
'method' => 'default_empty', 'method' => 'default_empty',
'breadcrumb' => TRUE, // generate a breadcrumb to here // Generate a breadcrumb to here.
'breadcrumb' => TRUE,
), ),
'access denied' => array( 'access denied' => array(
'title' => t('Display "Access Denied"'), 'title' => t('Display "Access Denied"'),
'method' => 'default_access_denied', 'method' => 'default_access_denied',
'breadcrumb' => FALSE, // generate a breadcrumb to here // Generate a breadcrumb to here.
'breadcrumb' => FALSE,
), ),
); );
@ -543,10 +593,11 @@ class views_handler_argument extends views_handler {
} }
/** /**
* Provide a form for selecting the default argument when the * Provide a form for selecting the default argument.
* default action is set to provide default argument. *
* Used when the default action is set to provide default argument.
*/ */
function default_argument_form(&$form, &$form_state) { public function default_argument_form(&$form, &$form_state) {
$plugins = views_fetch_plugin_data('argument default'); $plugins = views_fetch_plugin_data('argument default');
$options = array(); $options = array();
@ -554,7 +605,7 @@ class views_handler_argument extends views_handler {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Skip default argument for view URL'), '#title' => t('Skip default argument for view URL'),
'#default_value' => $this->options['default_argument_skip_url'], '#default_value' => $this->options['default_argument_skip_url'],
'#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.') '#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.'),
); );
$form['default_argument_type'] = array( $form['default_argument_type'] = array(
@ -564,8 +615,11 @@ class views_handler_argument extends views_handler {
'#id' => 'edit-options-default-argument-type', '#id' => 'edit-options-default-argument-type',
'#title' => t('Type'), '#title' => t('Type'),
'#default_value' => $this->options['default_argument_type'], '#default_value' => $this->options['default_argument_type'],
'#dependency' => array(
'#dependency' => array('radio:options[default_action]' => array('default')), 'radio:options[default_action]' => array(
'default',
),
),
// Views custom key, moves this element to the appropriate container // Views custom key, moves this element to the appropriate container
// under the radio button. // under the radio button.
'#argument_option' => 'default', '#argument_option' => 'default',
@ -588,7 +642,7 @@ class views_handler_argument extends views_handler {
'#input' => TRUE, '#input' => TRUE,
'#dependency' => array( '#dependency' => array(
'radio:options[default_action]' => array('default'), 'radio:options[default_action]' => array('default'),
'edit-options-default-argument-type' => array($id) 'edit-options-default-argument-type' => array($id),
), ),
'#dependency_count' => 2, '#dependency_count' => 2,
); );
@ -603,10 +657,10 @@ class views_handler_argument extends views_handler {
} }
/** /**
* Provide a form for selecting further summary options when the * Provide a form for selecting further summary options when the default
* default action is set to display one. * action is set to display one.
*/ */
function default_summary_form(&$form, &$form_state) { public function default_summary_form(&$form, &$form_state) {
$style_plugins = views_fetch_plugin_data('style'); $style_plugins = views_fetch_plugin_data('style');
$summary_plugins = array(); $summary_plugins = array();
$format_options = array(); $format_options = array();
@ -635,7 +689,7 @@ class views_handler_argument extends views_handler {
'#default_value' => $this->options['summary']['number_of_records'], '#default_value' => $this->options['summary']['number_of_records'],
'#options' => array( '#options' => array(
0 => $this->get_sort_name(), 0 => $this->get_sort_name(),
1 => t('Number of records') 1 => t('Number of records'),
), ),
'#dependency' => array('radio:options[default_action]' => array('summary')), '#dependency' => array('radio:options[default_action]' => array('summary')),
); );
@ -659,7 +713,8 @@ class views_handler_argument extends views_handler {
'#suffix' => '</div>', '#suffix' => '</div>',
'#id' => 'edit-options-summary-options-' . $id, '#id' => 'edit-options-summary-options-' . $id,
'#type' => 'item', '#type' => 'item',
'#input' => TRUE, // trick it into checking input to make #process run // Trick it into checking input to make #process run.
'#input' => TRUE,
'#dependency' => array( '#dependency' => array(
'radio:options[default_action]' => array('summary'), 'radio:options[default_action]' => array('summary'),
'radio:options[summary][format]' => array($id), 'radio:options[summary][format]' => array($id),
@ -677,11 +732,11 @@ class views_handler_argument extends views_handler {
* *
* Override this method only with extreme care. * Override this method only with extreme care.
* *
* @return * @return bool
* A boolean value; if TRUE, continue building this view. If FALSE, * A boolean value; if TRUE, continue building this view. If FALSE,
* building the view will be aborted here. * building the view will be aborted here.
*/ */
function default_action($info = NULL) { public function default_action($info = NULL) {
if (!isset($info)) { if (!isset($info)) {
$info = $this->default_actions($this->options['default_action']); $info = $this->default_actions($this->options['default_action']);
} }
@ -699,29 +754,30 @@ class views_handler_argument extends views_handler {
} }
/** /**
* How to act if validation failes * How to act if validation fails.
*/ */
function validate_fail() { public function validate_fail() {
$info = $this->default_actions($this->options['validate']['fail']); $info = $this->default_actions($this->options['validate']['fail']);
return $this->default_action($info); return $this->default_action($info);
} }
/** /**
* Default action: ignore. * Default action: ignore.
* *
* If an argument was expected and was not given, in this case, simply * If an argument was expected and was not given, in this case, simply ignore
* ignore the argument entirely. * the argument entirely.
*/ */
function default_ignore() { public function default_ignore() {
return TRUE; return TRUE;
} }
/** /**
* Default action: not found. * Default action: not found.
* *
* If an argument was expected and was not given, in this case, report * If an argument was expected and was not given, in this case, report the
* the view as 'not found' or hide it. * view as 'not found' or hide it.
*/ */
function default_not_found() { public function default_not_found() {
// Set a failure condition and let the display manager handle it. // Set a failure condition and let the display manager handle it.
$this->view->build_info['fail'] = TRUE; $this->view->build_info['fail'] = TRUE;
return FALSE; return FALSE;
@ -730,10 +786,10 @@ class views_handler_argument extends views_handler {
/** /**
* Default action: access denied. * Default action: access denied.
* *
* If an argument was expected and was not given, in this case, report * If an argument was expected and was not given, in this case, report the
* the view as 'access denied'. * view as 'access denied'.
*/ */
function default_access_denied() { public function default_access_denied() {
$this->view->build_info['denied'] = TRUE; $this->view->build_info['denied'] = TRUE;
return FALSE; return FALSE;
} }
@ -741,10 +797,10 @@ class views_handler_argument extends views_handler {
/** /**
* Default action: empty * Default action: empty
* *
* If an argument was expected and was not given, in this case, display * If an argument was expected and was not given, in this case, display the
* the view's empty text * view's empty text
*/ */
function default_empty() { public function default_empty() {
// We return with no query; this will force the empty text. // We return with no query; this will force the empty text.
$this->view->built = TRUE; $this->view->built = TRUE;
$this->view->executed = TRUE; $this->view->executed = TRUE;
@ -753,17 +809,20 @@ class views_handler_argument extends views_handler {
} }
/** /**
* This just returns true. The view argument builder will know where * This just returns true.
* to find the argument from. *
* The view argument builder will know where to find the argument from.
*
* @todo Why is this needed?
*/ */
function default_default() { public function default_default() {
return TRUE; return TRUE;
} }
/** /**
* Determine if the argument is set to provide a default argument. * Determine if the argument is set to provide a default argument.
*/ */
function has_default_argument() { public function has_default_argument() {
$info = $this->default_actions($this->options['default_action']); $info = $this->default_actions($this->options['default_action']);
return !empty($info['has default argument']); return !empty($info['has default argument']);
} }
@ -771,7 +830,7 @@ class views_handler_argument extends views_handler {
/** /**
* Get a default argument, if available. * Get a default argument, if available.
*/ */
function get_default_argument() { public function get_default_argument() {
$plugin = $this->get_plugin('argument default'); $plugin = $this->get_plugin('argument default');
if ($plugin) { if ($plugin) {
return $plugin->get_argument(); return $plugin->get_argument();
@ -784,7 +843,7 @@ class views_handler_argument extends views_handler {
* For example, the validation plugin may want to alter an argument for use in * For example, the validation plugin may want to alter an argument for use in
* the URL. * the URL.
*/ */
function process_summary_arguments(&$args) { public function process_summary_arguments(&$args) {
if ($this->options['validate']['type'] != 'none') { if ($this->options['validate']['type'] != 'none') {
if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) { if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) {
$this->validator->process_summary_arguments($args); $this->validator->process_summary_arguments($args);
@ -795,20 +854,19 @@ class views_handler_argument extends views_handler {
/** /**
* Default action: summary. * Default action: summary.
* *
* If an argument was expected and was not given, in this case, display * If an argument was expected and was not given, in this case, display a
* a summary query. * summary query.
*/ */
function default_summary() { public function default_summary() {
$this->view->build_info['summary'] = TRUE; $this->view->build_info['summary'] = TRUE;
$this->view->build_info['summary_level'] = $this->options['id']; $this->view->build_info['summary_level'] = $this->options['id'];
// Change the display style to the summary style for this // Change the display style to the summary style for this argument.
// argument.
$this->view->plugin_name = $this->options['summary']['format']; $this->view->plugin_name = $this->options['summary']['format'];
$this->view->style_options = $this->options['summary_options']; $this->view->style_options = $this->options['summary_options'];
// Clear out the normal primary field and whatever else may have // Clear out the normal primary field and whatever else may have been added
// been added and let the summary do the work. // and let the summary do the work.
$this->query->clear_fields(); $this->query->clear_fields();
$this->summary_query(); $this->summary_query();
@ -826,14 +884,14 @@ class views_handler_argument extends views_handler {
* *
* This must: * This must:
* - add_groupby: group on this field in order to create summaries. * - add_groupby: group on this field in order to create summaries.
* - add_field: add a 'num_nodes' field for the count. Usually it will * - add_field: add a 'num_nodes' field for the count. Usually it will be a
* be a count on $view->base_field * count on $view->base_field
* - set_count_field: Reset the count field so we get the right paging. * - set_count_field: Reset the count field so we get the right paging.
* *
* @return * @return string
* The alias used to get the number of records (count) for this entry. * The alias used to get the number of records (count) for this entry.
*/ */
function summary_query() { public function summary_query() {
$this->ensure_my_table(); $this->ensure_my_table();
// Add the field. // Add the field.
$this->base_alias = $this->query->add_field($this->table_alias, $this->real_field); $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
@ -844,15 +902,15 @@ class views_handler_argument extends views_handler {
/** /**
* Add the name field, which is the field displayed in summary queries. * Add the name field, which is the field displayed in summary queries.
*
* This is often used when the argument is numeric. * This is often used when the argument is numeric.
*/ */
function summary_name_field() { public function summary_name_field() {
// Add the 'name' field. For example, if this is a uid argument, the // Add the 'name' field. For example, if this is a uid argument, the name
// name field would be 'name' (i.e, the username). // field would be 'name' (i.e, the username).
if (isset($this->name_table)) { if (isset($this->name_table)) {
// if the alias is different then we're probably added, not ensured, // If the alias is different then we're probably added, not ensured, so
// so look up the join and add it instead. // look up the join and add it instead.
if ($this->table_alias != $this->name_table) { if ($this->table_alias != $this->name_table) {
$j = views_get_table_join($this->name_table, $this->table); $j = views_get_table_join($this->name_table, $this->table);
if ($j) { if ($j) {
@ -878,15 +936,21 @@ class views_handler_argument extends views_handler {
} }
/** /**
* Some basic summary behavior that doesn't need to be repeated as much as * Some basic summary behavior.
* code that goes into summary_query() *
* This doesn't need to be repeated as much as code that goes into
* summary_query().
*/ */
function summary_basics($count_field = TRUE) { public function summary_basics($count_field = TRUE) {
// Add the number of nodes counter // Add the number of nodes counter.
$distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct)); $distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct));
$count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records', $count_alias = $this->query->add_field($this->query->base_table,
array('count' => TRUE, 'distinct' => $distinct)); $this->query->base_field, 'num_records',
array(
'count' => TRUE,
'distinct' => $distinct,
));
$this->query->add_groupby($this->name_alias); $this->query->add_groupby($this->name_alias);
if ($count_field) { if ($count_field) {
@ -897,36 +961,42 @@ class views_handler_argument extends views_handler {
} }
/** /**
* Sorts the summary based upon the user's selection. The base variant of * Sorts the summary based upon the user's selection.
* this is usually adequte.
* *
* @param $order * The base variant of this is usually adequte.
*
* @param string $order
* The order selected in the UI. * The order selected in the UI.
*/ */
function summary_sort($order, $by = NULL) { public function summary_sort($order, $by = NULL) {
$this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias)); $this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias));
} }
/** /**
* Provide the argument to use to link from the summary to the next level; * 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 *
* This will be called once per row of a summary, and used as part of
* $view->get_url(). * $view->get_url().
* *
* @param $data * @param object $data
* The query results for the row. * The query results for the row.
*/ */
function summary_argument($data) { public function summary_argument($data) {
return $data->{$this->base_alias}; return $data->{$this->base_alias};
} }
/** /**
* Provides the name to use for the summary. By default this is just * Provides the name to use for the summary.
* the name field.
* *
* @param $data * By default this is just the name field.
*
* @param object $data
* The query results for the row. * The query results for the row.
*
* @return string
* The summary.
*/ */
function summary_name($data) { public function summary_name($data) {
$value = $data->{$this->name_alias}; $value = $data->{$this->name_alias};
if (empty($value) && !empty($this->definition['empty field name'])) { if (empty($value) && !empty($this->definition['empty field name'])) {
$value = $this->definition['empty field name']; $value = $this->definition['empty field name'];
@ -938,8 +1008,11 @@ class views_handler_argument extends views_handler {
* Set up the query for this argument. * Set up the query for this argument.
* *
* The argument sent may be found at $this->argument. * The argument sent may be found at $this->argument.
*
* @param bool $group_by
* Whether the query uses a group-by.
*/ */
function query($group_by = FALSE) { public function query($group_by = FALSE) {
$this->ensure_my_table(); $this->ensure_my_table();
$this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument); $this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
} }
@ -949,15 +1022,17 @@ class views_handler_argument extends views_handler {
* *
* This usually needs to be overridden to provide a proper title. * This usually needs to be overridden to provide a proper title.
*/ */
function title() { public function title() {
return check_plain($this->argument); return check_plain($this->argument);
} }
/** /**
* Called by the view object to get the title. This may be set by a * Called by the view object to get the title.
* validator so we don't necessarily call through to title(). *
* This may be set by a validator so we don't necessarily call through to
* title().
*/ */
function get_title() { public function get_title() {
if (isset($this->validated_title)) { if (isset($this->validated_title)) {
return $this->validated_title; return $this->validated_title;
} }
@ -969,7 +1044,7 @@ class views_handler_argument extends views_handler {
/** /**
* Validate that this argument works. By default, all arguments are valid. * Validate that this argument works. By default, all arguments are valid.
*/ */
function validate_arg($arg) { public function validate_arg($arg) {
// By using % in URLs, arguments could be validated twice; this eases // By using % in URLs, arguments could be validated twice; this eases
// that pain. // that pain.
if (isset($this->argument_validated)) { if (isset($this->argument_validated)) {
@ -989,7 +1064,7 @@ class views_handler_argument extends views_handler {
return $this->argument_validated = $plugin->validate_argument($arg); return $this->argument_validated = $plugin->validate_argument($arg);
} }
// If the plugin isn't found, fall back to the basic validation path: // If the plugin isn't found, fall back to the basic validation path.
return $this->argument_validated = $this->validate_argument_basic($arg); return $this->argument_validated = $this->validate_argument_basic($arg);
} }
@ -997,10 +1072,10 @@ class views_handler_argument extends views_handler {
* Called by the menu system to validate an argument. * Called by the menu system to validate an argument.
* *
* This checks to see if this is a 'soft fail', which means that if the * 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, * argument fails to validate, but there is an action to take anyway, then
* then validation cannot actually fail. * validation cannot actually fail.
*/ */
function validate_argument($arg) { public function validate_argument($arg) {
$validate_info = $this->default_actions($this->options['validate']['fail']); $validate_info = $this->default_actions($this->options['validate']['fail']);
if (empty($validate_info['hard fail'])) { if (empty($validate_info['hard fail'])) {
return TRUE; return TRUE;
@ -1008,8 +1083,8 @@ class views_handler_argument extends views_handler {
$rc = $this->validate_arg($arg); $rc = $this->validate_arg($arg);
// If the validator has changed the validate fail condition to a // If the validator has changed the validate fail condition to a soft fail,
// soft fail, deal with that: // deal with that.
$validate_info = $this->default_actions($this->options['validate']['fail']); $validate_info = $this->default_actions($this->options['validate']['fail']);
if (empty($validate_info['hard fail'])) { if (empty($validate_info['hard fail'])) {
return TRUE; return TRUE;
@ -1021,11 +1096,14 @@ class views_handler_argument extends views_handler {
/** /**
* Provide a basic argument validation. * Provide a basic argument validation.
* *
* This can be overridden for more complex types; the basic * This can be overridden for more complex types; the basic validator only
* validator only checks to see if the argument is not NULL * checks to see if the argument is not NULL or is numeric if the definition
* or is numeric if the definition says it's numeric. * says it's numeric.
*
* @return bool
* Whether or not the argument validates.
*/ */
function validate_argument_basic($arg) { public function validate_argument_basic($arg) {
if (!isset($arg) || $arg === '') { if (!isset($arg) || $arg === '') {
return FALSE; return FALSE;
} }
@ -1040,17 +1118,21 @@ class views_handler_argument extends views_handler {
/** /**
* Set the input for this argument * Set the input for this argument
* *
* @return TRUE if it successfully validates; FALSE if it does not. * @return bool
* TRUE if it successfully validates; FALSE if it does not.
*/ */
function set_argument($arg) { public function set_argument($arg) {
$this->argument = $arg; $this->argument = $arg;
return $this->validate_arg($arg); return $this->validate_arg($arg);
} }
/** /**
* Get the value of this argument. * Get the value of this argument.
*
* @return string
* The value.
*/ */
function get_value() { public function get_value() {
// If we already processed this argument, we're done. // If we already processed this argument, we're done.
if (isset($this->argument)) { if (isset($this->argument)) {
return $this->argument; return $this->argument;
@ -1089,8 +1171,11 @@ class views_handler_argument extends views_handler {
* *
* Arguments can have styles for the summary view. This special export * Arguments can have styles for the summary view. This special export
* handler makes sure this works properly. * handler makes sure this works properly.
*
* @return string
* The export summary.
*/ */
function export_summary($indent, $prefix, $storage, $option, $definition, $parents) { public function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
$output = ''; $output = '';
$name = $this->options['summary'][$option]; $name = $this->options['summary'][$option];
$options = $this->options['summary_options']; $options = $this->options['summary_options'];
@ -1113,8 +1198,11 @@ class views_handler_argument extends views_handler {
* *
* Arguments use validation plugins. This special export handler makes sure * Arguments use validation plugins. This special export handler makes sure
* this works properly. * this works properly.
*
* @return string
* The validation response.
*/ */
function export_validation($indent, $prefix, $storage, $option, $definition, $parents) { public function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
$output = ''; $output = '';
$name = $this->options['validate'][$option]; $name = $this->options['validate'][$option];
$options = $this->options['validate_options']; $options = $this->options['validate_options'];
@ -1137,8 +1225,11 @@ class views_handler_argument extends views_handler {
* *
* Since style and validation plugins have their own export handlers, this * Since style and validation plugins have their own export handlers, this
* one is currently only used for default argument plugins. * one is currently only used for default argument plugins.
*
* @return string
* Export string.
*/ */
function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) { public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
$output = ''; $output = '';
if ($option == 'default_argument_type') { if ($option == 'default_argument_type') {
$type = 'argument default'; $type = 'argument default';
@ -1162,28 +1253,30 @@ class views_handler_argument extends views_handler {
/** /**
* Get the display or row plugin, if it exists. * Get the display or row plugin, if it exists.
*/ */
function get_plugin($type = 'argument default', $name = NULL) { public function get_plugin($type = 'argument default', $name = NULL) {
$options = array(); $options = array();
switch ($type) { switch ($type) {
case 'argument default': case 'argument default':
$plugin_name = $this->options['default_argument_type']; $plugin_name = $this->options['default_argument_type'];
$options_name = 'default_argument_options'; $options_name = 'default_argument_options';
break; break;
case 'argument validator': case 'argument validator':
$plugin_name = $this->options['validate']['type']; $plugin_name = $this->options['validate']['type'];
$options_name = 'validate_options'; $options_name = 'validate_options';
break; break;
case 'style': case 'style':
$plugin_name = $this->options['summary']['format']; $plugin_name = $this->options['summary']['format'];
$options_name = 'summary_options'; $options_name = 'summary_options';
break;
} }
if (!$name) { if (!$name) {
$name = $plugin_name; $name = $plugin_name;
} }
// we only fetch the options if we're fetching the plugin actually // We only fetch the options if we're fetching the plugin actually in use.
// in use.
if ($name == $plugin_name) { if ($name == $plugin_name) {
$options = $this->options[$options_name]; $options = $this->options[$options_name];
} }
@ -1206,10 +1299,14 @@ class views_handler_argument extends views_handler {
* *
* Subclasses should override this to specify what the default sort order of * Subclasses should override this to specify what the default sort order of
* their argument is (e.g. alphabetical, numeric, date). * their argument is (e.g. alphabetical, numeric, date).
*
* @return string
* The label for the sorter.
*/ */
function get_sort_name() { public function get_sort_name() {
return t('Default sort', array(), array('context' => 'Sort order')); return t('Default sort', array(), array('context' => 'Sort order'));
} }
} }
/** /**
@ -1218,22 +1315,44 @@ class views_handler_argument extends views_handler {
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_broken extends views_handler_argument { class views_handler_argument_broken extends views_handler_argument {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query($group_by = FALSE) { /* No query to run */ } * {@inheritdoc}
function options_form(&$form, &$form_state) { */
public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item description">' . 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.') . '</div>', '#markup' => '<div class="form-item description">' . 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.') . '</div>',
); );
} }
/** /**
* Determine if the handler is considered 'broken' * {@inheritdoc}
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }
/** /**

View File

@ -10,9 +10,9 @@
* *
* Adds an option to set a default argument based on the current date. * Adds an option to set a default argument based on the current date.
* *
* @param $arg_format * @param string $arg_format
* The format string to use on the current time when * The format string to use on the current time when creating a default date
* creating a default date argument. * argument.
* *
* Definitions terms: * Definitions terms:
* - many to one: If true, the "many to one" helper will be used. * - many to one: If true, the "many to one" helper will be used.
@ -24,27 +24,40 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_date extends views_handler_argument_formula { class views_handler_argument_date extends views_handler_argument_formula {
var $option_name = 'default_argument_date';
var $arg_format = 'Y-m-d'; /**
*
*/
public $option_name = 'default_argument_date';
/**
*
*/
public $arg_format = 'Y-m-d';
/** /**
* Add an option to set the default value to the current date. * Add an option to set the default value to the current date.
*/ */
function default_argument_form(&$form, &$form_state) { public function default_argument_form(&$form, &$form_state) {
parent::default_argument_form($form, $form_state); parent::default_argument_form($form, $form_state);
$form['default_argument_type']['#options'] += array('date' => t('Current date')); $form['default_argument_type']['#options'] += array('date' => t('Current date'));
$form['default_argument_type']['#options'] += array('node_created' => t("Current node's creation time")); $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")); } $form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time"));
}
/** /**
* Set the empty argument value to the current date, * Set the empty argument value to the current date,
*
* formatted appropriately for this argument. * formatted appropriately for this argument.
*
* @return string
* The default argument.
*/ */
function get_default_argument($raw = FALSE) { public function get_default_argument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') { if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->arg_format, REQUEST_TIME); return date($this->arg_format, REQUEST_TIME);
} }
else if (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) { elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
foreach (range(1, 3) as $i) { foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i); $node = menu_get_object('node', $i);
if (!empty($node)) { if (!empty($node)) {
@ -71,11 +84,12 @@ class views_handler_argument_date extends views_handler_argument_formula {
} }
/** /**
* The date handler provides some default argument types, which aren't argument default plugins, * Adapt the export mechanism.
* so addapt the export mechanism. *
* The date handler provides some default argument types, which aren't
* argument default plugins.
*/ */
function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) { public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
// Only use a special behaviour for the special argument types, else just // Only use a special behaviour for the special argument types, else just
// use the default behaviour. // use the default behaviour.
if ($option == 'default_argument_type') { if ($option == 'default_argument_type') {
@ -94,8 +108,11 @@ class views_handler_argument_date extends views_handler_argument_formula {
return parent::export_plugin($indent, $prefix, $storage, $option, $definition, $parents); return parent::export_plugin($indent, $prefix, $storage, $option, $definition, $parents);
} }
/**
function get_sort_name() { * {@inheritdoc}
*/
public function get_sort_name() {
return t('Date', array(), array('context' => 'Sort order')); return t('Date', array(), array('context' => 'Sort order'));
} }
} }

View File

@ -16,11 +16,16 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_formula extends views_handler_argument { class views_handler_argument_formula extends views_handler_argument {
var $formula = NULL;
/** /**
* Constructor *
*/ */
function construct() { public $formula = NULL;
/**
* {@inheritdoc}
*/
public function construct() {
parent::construct(); parent::construct();
if (!empty($this->definition['formula'])) { if (!empty($this->definition['formula'])) {
@ -28,14 +33,17 @@ class views_handler_argument_formula extends views_handler_argument {
} }
} }
function get_formula() { /**
*
*/
public function get_formula() {
return str_replace('***table***', $this->table_alias, $this->formula); return str_replace('***table***', $this->table_alias, $this->formula);
} }
/** /**
* Build the summary query based on a formula * Build the summary query based on a formula
*/ */
function summary_query() { public function summary_query() {
$this->ensure_my_table(); $this->ensure_my_table();
// Now that our table is secure, get our formula. // Now that our table is secure, get our formula.
$formula = $this->get_formula(); $formula = $this->get_formula();
@ -50,14 +58,15 @@ class views_handler_argument_formula extends views_handler_argument {
/** /**
* Build the query based upon the formula * Build the query based upon the formula
*/ */
function query($group_by = FALSE) { public function query($group_by = FALSE) {
$this->ensure_my_table(); $this->ensure_my_table();
// Now that our table is secure, get our formula. // Now that our table is secure, get our formula.
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$formula = $this->get_formula() .' = ' . $placeholder; $formula = $this->get_formula() . ' = ' . $placeholder;
$placeholders = array( $placeholders = array(
$placeholder => $this->argument, $placeholder => $this->argument,
); );
$this->query->add_where(0, $formula, $placeholders, 'formula'); $this->query->add_where(0, $formula, $placeholders, 'formula');
} }
} }

View File

@ -10,8 +10,12 @@
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_group_by_numeric extends views_handler_argument { class views_handler_argument_group_by_numeric extends views_handler_argument {
function query($group_by = FALSE) {
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
$this->ensure_my_table(); $this->ensure_my_table();
$field = $this->get_field(); $field = $this->get_field();
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
@ -19,11 +23,18 @@ class views_handler_argument_group_by_numeric extends views_handler_argument {
$this->query->add_having_expression(0, "$field = $placeholder", array($placeholder => $this->argument)); $this->query->add_having_expression(0, "$field = $placeholder", array($placeholder => $this->argument));
} }
function ui_name($short = FALSE) { /**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return $this->get_field(parent::ui_name($short)); return $this->get_field(parent::ui_name($short));
} }
function get_sort_name() { /**
* {@inheritdoc}
*/
public function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order')); return t('Numerical', array(), array('context' => 'Sort order'));
} }
} }

View File

@ -6,29 +6,39 @@
*/ */
/** /**
* An argument handler for use in fields that have a many to one relationship * Argument handler for fields that have many-to-one table relationships.
* with the table(s) to the left. This adds a bunch of options that are *
* reasonably common with this type of relationship. * (i.e. with the table(s) to the left.)
* This adds a bunch of options that are reasonably common with this type of
* relationship.
*
* Definition terms: * Definition terms:
* - numeric: If true, the field will be considered numeric. Probably should * - numeric: If true, the field will be considered numeric. Probably should
* always be set TRUE as views_handler_argument_string has many to one * always be set TRUE as views_handler_argument_string has many to one
* capabilities. * capabilities.
* - zero is null: If true, a 0 will be handled as empty, so for example * - zero is null: If true, a 0 will be handled as empty, so for example a
* a default argument can be provided or a summary can be shown. * default argument can be provided or a summary can be shown.
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_many_to_one extends views_handler_argument { class views_handler_argument_many_to_one extends views_handler_argument {
function init(&$view, &$options) {
/**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
$this->helper = new views_many_to_one_helper($this); $this->helper = new views_many_to_one_helper($this);
// Ensure defaults for these, during summaries and stuff: // Ensure defaults for these, during summaries and stuff.
$this->operator = 'or'; $this->operator = 'or';
$this->value = array(); $this->value = array();
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
if (!empty($this->definition['numeric'])) { if (!empty($this->definition['numeric'])) {
@ -49,7 +59,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// allow + for or, , for and // allow + for or, , for and
@ -85,11 +98,14 @@ class views_handler_argument_many_to_one extends views_handler_argument {
* Override ensure_my_table so we can control how this joins in. * Override ensure_my_table so we can control how this joins in.
* The operator actually has influence over joining. * The operator actually has influence over joining.
*/ */
function ensure_my_table() { public function ensure_my_table() {
$this->helper->ensure_my_table(); $this->helper->ensure_my_table();
} }
function query($group_by = FALSE) { /**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
$empty = FALSE; $empty = FALSE;
if (isset($this->definition['zero is null']) && $this->definition['zero is null']) { if (isset($this->definition['zero is null']) && $this->definition['zero is null']) {
if (empty($this->argument)) { if (empty($this->argument)) {
@ -118,7 +134,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
$this->helper->add_filter(); $this->helper->add_filter();
} }
function title() { /**
* {@inheritdoc}
*/
public function title() {
if (!$this->argument) { if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
} }
@ -144,7 +163,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query()); return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query());
} }
function summary_query() { /**
* {@inheritdoc}
*/
public function summary_query() {
$field = $this->table . '.' . $this->field; $field = $this->table . '.' . $this->field;
$join = $this->get_join(); $join = $this->get_join();
@ -167,7 +189,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
return $this->summary_basics(); return $this->summary_basics();
} }
function summary_argument($data) { /**
* {@inheritdoc}
*/
public function summary_argument($data) {
$value = $data->{$this->base_alias}; $value = $data->{$this->base_alias};
if (empty($value)) { if (empty($value)) {
$value = 0; $value = 0;
@ -179,7 +204,8 @@ class views_handler_argument_many_to_one extends views_handler_argument {
/** /**
* Override for specific title lookups. * Override for specific title lookups.
*/ */
function title_query() { public function title_query() {
return $this->value; return $this->value;
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_null extends views_handler_argument { class views_handler_argument_null extends views_handler_argument {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['must_not_be'] = array('default' => FALSE, 'bool' => TRUE); $options['must_not_be'] = array('default' => FALSE, 'bool' => TRUE);
return $options; return $options;
@ -21,7 +25,7 @@ class views_handler_argument_null extends views_handler_argument {
* Override options_form() so that only the relevant options * Override options_form() so that only the relevant options
* are displayed to the user. * are displayed to the user.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['must_not_be'] = array( $form['must_not_be'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
@ -38,7 +42,7 @@ class views_handler_argument_null extends views_handler_argument {
* Override default_actions() to remove actions that don't * Override default_actions() to remove actions that don't
* make sense for a null argument. * make sense for a null argument.
*/ */
function default_actions($which = NULL) { public function default_actions($which = NULL) {
if ($which) { if ($which) {
if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) { if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) {
return parent::default_actions($which); return parent::default_actions($which);
@ -51,7 +55,10 @@ class views_handler_argument_null extends views_handler_argument {
return $actions; return $actions;
} }
function validate_argument_basic($arg) { /**
* {@inheritdoc}
*/
public function validate_argument_basic($arg) {
if (!empty($this->options['must_not_be'])) { if (!empty($this->options['must_not_be'])) {
return !isset($arg); return !isset($arg);
} }
@ -63,5 +70,7 @@ class views_handler_argument_null extends views_handler_argument {
* Override the behavior of query() to prevent the query * Override the behavior of query() to prevent the query
* from being changed in any way. * from being changed in any way.
*/ */
function query($group_by = FALSE) {} public function query($group_by = FALSE) {
}
} }

View File

@ -6,25 +6,30 @@
*/ */
/** /**
* Basic argument handler for arguments that are numeric. Incorporates * Basic argument handler for arguments that are numeric.
* break_phrase. *
* Incorporates break_phrase.
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_numeric extends views_handler_argument { class views_handler_argument_numeric extends views_handler_argument {
/** /**
* The operator used for the query: or|and. * The operator used for the query: or|and.
* @var string * @var string
*/ */
var $operator; public $operator;
/** /**
* The actual value which is used for querying. * The actual value which is used for querying.
* @var array * @var array
*/ */
var $value; public $value;
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE); $options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE);
@ -33,7 +38,10 @@ class views_handler_argument_numeric extends views_handler_argument {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// allow + for or, , for and // allow + for or, , for and
@ -54,7 +62,10 @@ class views_handler_argument_numeric extends views_handler_argument {
); );
} }
function title() { /**
* {@inheritdoc}
*/
public function title() {
if (!$this->argument) { if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
} }
@ -80,14 +91,18 @@ class views_handler_argument_numeric extends views_handler_argument {
/** /**
* Override for specific title lookups. * Override for specific title lookups.
*
* @return array * @return array
* Returns all titles, if it's just one title it's an array with one entry. * Returns all titles, if it's just one title it's an array with one entry.
*/ */
function title_query() { public function title_query() {
return $this->value; return $this->value;
} }
function query($group_by = FALSE) { /**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
$this->ensure_my_table(); $this->ensure_my_table();
if (!empty($this->options['break_phrase'])) { if (!empty($this->options['break_phrase'])) {
@ -110,7 +125,11 @@ class views_handler_argument_numeric extends views_handler_argument {
} }
} }
function get_sort_name() { /**
* {@inheritdoc}
*/
public function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order')); return t('Numerical', array(), array('context' => 'Sort order'));
} }
} }

View File

@ -6,24 +6,30 @@
*/ */
/** /**
* Basic argument handler to implement string arguments that may have length * Argument handler to implement string arguments that may have length limits.
* limits.
* *
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_string extends views_handler_argument { class views_handler_argument_string extends views_handler_argument {
function init(&$view, &$options) {
/**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
if (!empty($this->definition['many to one'])) { if (!empty($this->definition['many to one'])) {
$this->helper = new views_many_to_one_helper($this); $this->helper = new views_many_to_one_helper($this);
// Ensure defaults for these, during summaries and stuff: // Ensure defaults for these, during summaries and stuff.
$this->operator = 'or'; $this->operator = 'or';
$this->value = array(); $this->value = array();
} }
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['glossary'] = array('default' => FALSE, 'bool' => TRUE); $options['glossary'] = array('default' => FALSE, 'bool' => TRUE);
@ -41,7 +47,10 @@ class views_handler_argument_string extends views_handler_argument {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['glossary'] = array( $form['glossary'] = array(
@ -126,9 +135,9 @@ class views_handler_argument_string extends views_handler_argument {
} }
/** /**
* Build the summary query based on a string * Build the summary query based on a string.
*/ */
function summary_query() { public function summary_query() {
if (empty($this->definition['many to one'])) { if (empty($this->definition['many to one'])) {
$this->ensure_my_table(); $this->ensure_my_table();
} }
@ -157,14 +166,14 @@ class views_handler_argument_string extends views_handler_argument {
* *
* $this->ensure_my_table() MUST have been called prior to this. * $this->ensure_my_table() MUST have been called prior to this.
*/ */
function get_formula() { public function get_formula() {
return "SUBSTRING($this->table_alias.$this->real_field, 1, " . intval($this->options['limit']) . ")"; return "SUBSTRING($this->table_alias.$this->real_field, 1, " . intval($this->options['limit']) . ")";
} }
/** /**
* Build the query based upon the formula * Build the query based upon the formula
*/ */
function query($group_by = FALSE) { public function query($group_by = FALSE) {
$argument = $this->argument; $argument = $this->argument;
if (!empty($this->options['transform_dash'])) { if (!empty($this->options['transform_dash'])) {
$argument = strtr($argument, '-', ' '); $argument = strtr($argument, '-', ' ');
@ -223,7 +232,10 @@ class views_handler_argument_string extends views_handler_argument {
} }
} }
function summary_argument($data) { /**
* {@inheritdoc}
*/
public function summary_argument($data) {
$value = $this->case_transform($data->{$this->base_alias}, $this->options['path_case']); $value = $this->case_transform($data->{$this->base_alias}, $this->options['path_case']);
if (!empty($this->options['transform_dash'])) { if (!empty($this->options['transform_dash'])) {
$value = strtr($value, ' ', '-'); $value = strtr($value, ' ', '-');
@ -231,11 +243,17 @@ class views_handler_argument_string extends views_handler_argument {
return $value; return $value;
} }
function get_sort_name() { /**
* {@inheritdoc}
*/
public function get_sort_name() {
return t('Alphabetical', array(), array('context' => 'Sort order')); return t('Alphabetical', array(), array('context' => 'Sort order'));
} }
function title() { /**
* {@inheritdoc}
*/
public function title() {
$this->argument = $this->case_transform($this->argument, $this->options['case']); $this->argument = $this->case_transform($this->argument, $this->options['case']);
if (!empty($this->options['transform_dash'])) { if (!empty($this->options['transform_dash'])) {
$this->argument = strtr($this->argument, '-', ' '); $this->argument = strtr($this->argument, '-', ' ');
@ -263,11 +281,14 @@ class views_handler_argument_string extends views_handler_argument {
/** /**
* Override for specific title lookups. * Override for specific title lookups.
*/ */
function title_query() { public function title_query() {
return drupal_map_assoc($this->value, 'check_plain'); return drupal_map_assoc($this->value, 'check_plain');
} }
function summary_name($data) { /**
* {@inheritdoc}
*/
public function summary_name($data) {
return $this->case_transform(parent::summary_name($data), $this->options['case']); return $this->case_transform(parent::summary_name($data), $this->options['case']);
} }

View File

@ -2,25 +2,26 @@
/** /**
* @file * @file
* @todo. * Definition of views_handler_field.
*/ */
/** /**
* @defgroup views_field_handlers Views field handlers * @defgroup views_field_handlers Views field handlers
* @{ * @{
* Handlers to tell Views how to build and display fields. * Handlers to tell Views how to build and display fields.
*
*/ */
/** /**
* Indicator of the render_text() method for rendering a single item. * Indicator of the render_text() method for rendering a single item.
* (If no render_item() is present). *
* If no render_item() is present.
*/ */
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0); define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
/** /**
* Indicator of the render_text() method for rendering the whole element. * Indicator of the render_text() method for rendering the whole element.
* (if no render_item() method is available). *
* if no render_item() method is available.
*/ */
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1); define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
@ -34,17 +35,29 @@ define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
* *
* Definition terms: * Definition terms:
* - additional fields: An array of fields that should be added to the query * - additional fields: An array of fields that should be added to the query
* for some purpose. The array is in the form of: * for some purpose. The array is in the form of:
* array('identifier' => array('table' => tablename, * array(
* 'field' => fieldname); as many fields as are necessary * 'identifier' => array(
* may be in this array. * 'table' => tablename,
* 'field' => fieldname,
* )
* );
* with as many fields as are necessary may be in this array.
* - click sortable: If TRUE, this field may be click sorted. * - click sortable: If TRUE, this field may be click sorted.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field extends views_handler { class views_handler_field extends views_handler {
var $field_alias = 'unknown';
var $aliases = array(); /**
*
*/
public $field_alias = 'unknown';
/**
*
*/
public $aliases = array();
/** /**
* The field value prior to any rewriting. * The field value prior to any rewriting.
@ -58,12 +71,12 @@ class views_handler_field extends views_handler {
* Stores additional fields which get's added to the query. * Stores additional fields which get's added to the query.
* The generated aliases are stored in $aliases. * The generated aliases are stored in $aliases.
*/ */
var $additional_fields = array(); public $additional_fields = array();
/** /**
* Construct a new field handler. * Construct a new field handler.
*/ */
function construct() { public function construct() {
parent::construct(); parent::construct();
$this->additional_fields = array(); $this->additional_fields = array();
@ -79,21 +92,24 @@ class views_handler_field extends views_handler {
/** /**
* Determine if this field can allow advanced rendering. * Determine if this field can allow advanced rendering.
* *
* Fields can set this to FALSE if they do not wish to allow * Fields can set this to FALSE if they do not wish to allow token based
* token based rewriting or link-making. * rewriting or link-making.
*/ */
function allow_advanced_render() { public function allow_advanced_render() {
return TRUE; return TRUE;
} }
function init(&$view, &$options) { /**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
} }
/** /**
* Called to add the field to a query. * Called to add the field to a query.
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
// Add the field. // Add the field.
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array(); $params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
@ -105,16 +121,15 @@ class views_handler_field extends views_handler {
/** /**
* Add 'additional' fields to the query. * Add 'additional' fields to the query.
* *
* @param $fields * @param array $fields
* An array of fields. The key is an identifier used to later find the * An array of fields. The key is an identifier used to later find the field
* field alias used. The value is either a string in which case it's * alias used. The value is either a string in which case it's assumed to be
* assumed to be a field on this handler's table; or it's an array in the * a field on this handler's table; or it's an array in the form of
* form of * @code array('table' => $tablename, 'field' => $fieldname) @endcode
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
*/ */
function add_additional_fields($fields = NULL) { public function add_additional_fields($fields = NULL) {
if (!isset($fields)) { if (!isset($fields)) {
// notice check // Notice check.
if (empty($this->additional_fields)) { if (empty($this->additional_fields)) {
return; return;
} }
@ -139,7 +154,12 @@ class views_handler_field extends views_handler {
} }
if (empty($table_alias)) { if (empty($table_alias)) {
debug(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']))); $t_args = array(
'@handler' => $this->definition['handler'],
'@identifier' => $identifier,
'@table' => $info['table'],
);
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', $t_args));
$this->aliases[$identifier] = 'broken'; $this->aliases[$identifier] = 'broken';
continue; continue;
} }
@ -162,7 +182,7 @@ class views_handler_field extends views_handler {
/** /**
* Called to determine what to tell the clicksorter. * Called to determine what to tell the clicksorter.
*/ */
function click_sort($order) { public function click_sort($order) {
if (isset($this->field_alias)) { if (isset($this->field_alias)) {
// Since fields should always have themselves already added, just // Since fields should always have themselves already added, just
// add a sort on the field. // add a sort on the field.
@ -174,14 +194,14 @@ class views_handler_field extends views_handler {
/** /**
* Determine if this field is click sortable. * Determine if this field is click sortable.
*/ */
function click_sortable() { public function click_sortable() {
return !empty($this->definition['click sortable']); return !empty($this->definition['click sortable']);
} }
/** /**
* Get this field's label. * Get this field's label.
*/ */
function label() { public function label() {
if (!isset($this->options['label'])) { if (!isset($this->options['label'])) {
return ''; return '';
} }
@ -191,7 +211,7 @@ class views_handler_field extends views_handler {
/** /**
* Return an HTML element based upon the field's element type. * Return an HTML element based upon the field's element type.
*/ */
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) { public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
if ($none_supported) { if ($none_supported) {
if ($this->options['element_type'] === '0') { if ($this->options['element_type'] === '0') {
return ''; return '';
@ -219,7 +239,7 @@ class views_handler_field extends views_handler {
/** /**
* Return an HTML element for the label based upon the field's element type. * Return an HTML element for the label based upon the field's element type.
*/ */
function element_label_type($none_supported = FALSE, $default_empty = FALSE) { public function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) { if ($none_supported) {
if ($this->options['element_label_type'] === '0') { if ($this->options['element_label_type'] === '0') {
return ''; return '';
@ -239,7 +259,7 @@ class views_handler_field extends views_handler {
/** /**
* Return an HTML element for the wrapper based upon the field's element type. * Return an HTML element for the wrapper based upon the field's element type.
*/ */
function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) { public function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) { if ($none_supported) {
if ($this->options['element_wrapper_type'] === '0') { if ($this->options['element_wrapper_type'] === '0') {
return 0; return 0;
@ -259,11 +279,10 @@ class views_handler_field extends views_handler {
/** /**
* Provide a list of elements valid for field HTML. * Provide a list of elements valid for field HTML.
* *
* This function can be overridden by fields that want more or fewer * This function can be overridden by fields that want more or fewer elements
* elements available, though this seems like it would be an incredibly * available, though this seems like it would be an incredibly rare occurence.
* rare occurence.
*/ */
function get_elements() { public function get_elements() {
static $elements = NULL; static $elements = NULL;
if (!isset($elements)) { if (!isset($elements)) {
$elements = variable_get('views_field_rewrite_elements', array( $elements = variable_get('views_field_rewrite_elements', array(
@ -289,7 +308,7 @@ class views_handler_field extends views_handler {
/** /**
* Return the class of the field. * Return the class of the field.
*/ */
function element_classes($row_index = NULL) { public function element_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_class']); $classes = explode(' ', $this->options['element_class']);
foreach ($classes as &$class) { foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index); $class = $this->tokenize_value($class, $row_index);
@ -304,15 +323,14 @@ class views_handler_field extends views_handler {
* This function actually figures out which field was last and uses its * This function actually figures out which field was last and uses its
* tokens so they will all be available. * tokens so they will all be available.
*/ */
function tokenize_value($value, $row_index = NULL) { public function tokenize_value($value, $row_index = NULL) {
if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) { if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
$fake_item = array( $fake_item = array(
'alter_text' => TRUE, 'alter_text' => TRUE,
'text' => $value, 'text' => $value,
); );
// Use isset() because empty() will trigger on 0 and 0 is // Use isset() because empty() will trigger on 0 and 0 is the first row.
// the first row.
if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) { if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
$tokens = $this->view->style_plugin->render_tokens[$row_index]; $tokens = $this->view->style_plugin->render_tokens[$row_index];
} }
@ -339,7 +357,7 @@ class views_handler_field extends views_handler {
/** /**
* Return the class of the field's label. * Return the class of the field's label.
*/ */
function element_label_classes($row_index = NULL) { public function element_label_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_label_class']); $classes = explode(' ', $this->options['element_label_class']);
foreach ($classes as &$class) { foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index); $class = $this->tokenize_value($class, $row_index);
@ -351,7 +369,7 @@ class views_handler_field extends views_handler {
/** /**
* Return the class of the field's wrapper. * Return the class of the field's wrapper.
*/ */
function element_wrapper_classes($row_index = NULL) { public function element_wrapper_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_wrapper_class']); $classes = explode(' ', $this->options['element_wrapper_class']);
foreach ($classes as &$class) { foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index); $class = $this->tokenize_value($class, $row_index);
@ -366,13 +384,14 @@ class views_handler_field extends views_handler {
* This api exists so that other modules can easy set the values of the field * This api exists so that other modules can easy set the values of the field
* without having the need to change the render method as well. * without having the need to change the render method as well.
* *
* @param $values * @param object $values
* An object containing all retrieved values. * An object containing all retrieved values.
* @param $field * @param string $field
* Optional name of the field where the value is stored. * Optional name of the field where the value is stored.
*/ */
function get_value($values, $field = NULL) { public function get_value($values, $field = NULL) {
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias; // $alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
$alias = isset($field) && isset($this->aliases[$field]) ? $this->aliases[$field] : $this->field_alias;
if (isset($values->{$alias})) { if (isset($values->{$alias})) {
return $values->{$alias}; return $values->{$alias};
} }
@ -383,13 +402,16 @@ class views_handler_field extends views_handler {
* by in the style settings. * by in the style settings.
* *
* @return bool * @return bool
* TRUE if this field handler is groupable, otherwise FALSE. * TRUE if this field handler is groupable, otherwise FALSE.
*/ */
function use_string_group_by() { public function use_string_group_by() {
return TRUE; return TRUE;
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE); $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
@ -447,10 +469,19 @@ class views_handler_field extends views_handler {
/** /**
* Performs some cleanup tasks on the options array before saving it. * Performs some cleanup tasks on the options array before saving it.
*/ */
function options_submit(&$form, &$form_state) { public function options_submit(&$form, &$form_state) {
$options = &$form_state['values']['options']; $options = &$form_state['values']['options'];
$types = array('element_type', 'element_label_type', 'element_wrapper_type'); $types = array(
$classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types); 'element_type',
'element_label_type',
'element_wrapper_type',
);
$base_types = array(
'element_class',
'element_label_class',
'element_wrapper_class',
);
$classes = array_combine($base_types, $types);
foreach ($types as $type) { foreach ($types as $type) {
if (!$options[$type . '_enable']) { if (!$options[$type . '_enable']) {
@ -471,10 +502,9 @@ class views_handler_field extends views_handler {
} }
/** /**
* Default options form that provides the label widget that all fields * Default options form provides the label widget that all fields should have.
* should have.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$label = $this->label(); $label = $this->label();
@ -581,7 +611,7 @@ class views_handler_field extends views_handler {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Create a CSS class'), '#title' => t('Create a CSS class'),
'#dependency' => array( '#dependency' => array(
'edit-options-element-label-type-enable' => array(1) 'edit-options-element-label-type-enable' => array(1),
), ),
'#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0', '#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings', '#fieldset' => 'style_settings',
@ -703,7 +733,7 @@ class views_handler_field extends views_handler {
'#title' => t('Replace spaces with dashes'), '#title' => t('Replace spaces with dashes'),
'#default_value' => $this->options['alter']['replace_spaces'], '#default_value' => $this->options['alter']['replace_spaces'],
'#dependency' => array( '#dependency' => array(
'edit-options-alter-make-link' => array(1) 'edit-options-alter-make-link' => array(1),
), ),
); );
$form['alter']['external'] = array( $form['alter']['external'] = array(
@ -722,7 +752,7 @@ class views_handler_field extends views_handler {
'#dependency' => array( '#dependency' => array(
'edit-options-alter-make-link' => array(1), 'edit-options-alter-make-link' => array(1),
), ),
'#options' => array( '#options' => array(
'none' => t('No transform'), 'none' => t('No transform'),
'upper' => t('Upper case'), 'upper' => t('Upper case'),
'lower' => t('Lower case'), 'lower' => t('Lower case'),
@ -796,7 +826,8 @@ class views_handler_field extends views_handler {
break; break;
} }
} }
$count = 0; // This lets us prepare the key as we want it printed. // This lets us prepare the key as we want it printed.
$count = 0;
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { 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 title', array('@argument' => $handler->ui_name()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
@ -819,15 +850,15 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
$output .= theme('item_list', $output .= theme('item_list',
array( array(
'items' => $items, 'items' => $items,
'type' => $type 'type' => $type,
)); ));
} }
} }
} }
// This construct uses 'hidden' and not markup because process doesn't // This construct uses 'hidden' and not markup because process doesn't
// run. It also has an extra div because the dependency wants to hide // run. It also has an extra div because the dependency wants to hide the
// the parent in situations like this, so we need a second div to // parent in situations like this, so we need a second div to make this
// make this work. // work.
$form['alter']['help'] = array( $form['alter']['help'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Replacement patterns'), '#title' => t('Replacement patterns'),
@ -997,28 +1028,29 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Provide extra data to the administration form * Provide extra data to the administration form
*/ */
function admin_summary() { public function admin_summary() {
return $this->label(); return $this->label();
} }
/** /**
* Run before any fields are rendered. * Run before any fields are rendered.
* *
* This gives the handlers some time to set up before any handler has * This gives the handlers some time to set up before any handler has been
* been rendered. * rendered.
* *
* @param $values * @param array $values
* An array of all objects returned from the query. * An array of all objects returned from the query.
*/ */
function pre_render(&$values) { } public function pre_render(&$values) {
}
/** /**
* Render the field. * Render the field.
* *
* @param $values * @param array $values
* The values retrieved from the database. * The values retrieved from the database.
*/ */
function render($values) { public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->sanitize_value($value); return $this->sanitize_value($value);
} }
@ -1029,7 +1061,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* This renders a field normally, then decides if render-as-link and * This renders a field normally, then decides if render-as-link and
* text-replacement rendering is necessary. * text-replacement rendering is necessary.
*/ */
function advanced_render($values) { public function advanced_render($values) {
if ($this->allow_advanced_render() && method_exists($this, 'render_item')) { if ($this->allow_advanced_render() && method_exists($this, 'render_item')) {
$raw_items = $this->get_items($values); $raw_items = $this->get_items($values);
// If there are no items, set the original value to NULL. // If there are no items, set the original value to NULL.
@ -1094,7 +1126,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Checks if a field value is empty. * Checks if a field value is empty.
* *
* @param $value * @param mixed $value
* The field value. * The field value.
* @param bool $empty_zero * @param bool $empty_zero
* Whether or not this field is configured to consider 0 as empty. * Whether or not this field is configured to consider 0 as empty.
@ -1102,9 +1134,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* Whether or not to use empty() to check the value. * Whether or not to use empty() to check the value.
* *
* @return bool * @return bool
* TRUE if the value is considered empty, FALSE otherwise. * TRUE if the value is considered empty, FALSE otherwise.
*/ */
function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) { public function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
if (!isset($value)) { if (!isset($value)) {
$empty = TRUE; $empty = TRUE;
} }
@ -1124,7 +1156,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* This is separated out as some fields may render lists, and this allows * This is separated out as some fields may render lists, and this allows
* each item to be handled individually. * each item to be handled individually.
*/ */
function render_text($alter) { public function render_text($alter) {
$value = $this->last_render; $value = $this->last_render;
if (!empty($alter['alter_text']) && $alter['text'] !== '') { if (!empty($alter['alter_text']) && $alter['text'] !== '') {
@ -1139,9 +1171,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
// Check if there should be no further rewrite for empty values. // Check if there should be no further rewrite for empty values.
$no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']); $no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']);
// Check whether the value is empty and return nothing, so the field isn't rendered. // Check whether the value is empty and return nothing, so the field isn't
// First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE). // rendered. First check whether the field should be hidden if the
// For numeric values you can specify whether "0"/0 should be empty. // value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty =
// FALSE). For numeric values you can specify whether "0"/0 should be empty.
if ((($this->options['hide_empty'] && empty($value)) if ((($this->options['hide_empty'] && empty($value))
|| ($alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty)) || ($alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty))
&& $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) { && $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
@ -1169,7 +1202,8 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
$more_link_path = $this->options['alter']['more_link_path']; $more_link_path = $this->options['alter']['more_link_path'];
$more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens))); $more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
// Take sure that paths which was runned through url() does work as well. // Take sure that paths which was runned through url() does work as
// well.
$base_path = base_path(); $base_path = base_path();
// Checks whether the path starts with the base_path. // Checks whether the path starts with the base_path.
if (strpos($more_link_path, $base_path) === 0) { if (strpos($more_link_path, $base_path) === 0) {
@ -1189,7 +1223,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
if (!empty($alter['make_link']) && !empty($alter['path'])) { if (!empty($alter['make_link']) && !empty($alter['path'])) {
if (!isset($tokens)) { if (!isset($tokens)) {
$tokens = $this->get_render_tokens($alter); $tokens = $this->get_render_tokens($alter);
} }
$value = $this->render_as_link($alter, $value, $tokens); $value = $this->render_as_link($alter, $value, $tokens);
} }
@ -1200,7 +1234,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Render this field as altered text, from a fieldset set by the user. * Render this field as altered text, from a fieldset set by the user.
*/ */
function render_altered($alter, $tokens) { public function render_altered($alter, $tokens) {
// Filter this right away as our substitutions are already sanitized. // Filter this right away as our substitutions are already sanitized.
$value = filter_xss_admin($alter['text']); $value = filter_xss_admin($alter['text']);
$value = strtr($value, $tokens); $value = strtr($value, $tokens);
@ -1211,21 +1245,20 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Trim the field down to the specified length. * Trim the field down to the specified length.
*/ */
function render_trim_text($alter, $value) { public function render_trim_text($alter, $value) {
if (!empty($alter['strip_tags'])) { if (!empty($alter['strip_tags'])) {
// NOTE: It's possible that some external fields might override the // NOTE: It's possible that some external fields might override the
// element type so if someone from, say, CCK runs into a bug here, // element type so if someone from, say, CCK runs into a bug here, this
// this may be why =) // may be why =)
$this->definition['element type'] = 'span'; $this->definition['element type'] = 'span';
} }
return views_trim_text($alter, $value); return views_trim_text($alter, $value);
} }
/** /**
* Render this field as a link, with the info from a fieldset set by * Render this field as a link, with info from a fieldset set by the user.
* the user.
*/ */
function render_as_link($alter, $text, $tokens) { public function render_as_link($alter, $text, $tokens) {
$value = ''; $value = '';
if (!empty($alter['prefix'])) { if (!empty($alter['prefix'])) {
@ -1243,9 +1276,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
// strip_tags() removes <front>, so check whether its different to front. // strip_tags() removes <front>, so check whether its different to front.
if ($path != '<front>') { if ($path != '<front>') {
// Use strip tags as there should never be HTML in the path. // Use strip tags as there should never be HTML in the path. However, we
// However, we need to preserve special characters like " that // need to preserve special characters like " that were removed by
// were removed by check_plain(). // check_plain().
$path = strip_tags(decode_entities(strtr($path, $tokens))); $path = strip_tags(decode_entities(strtr($path, $tokens)));
if (!empty($alter['path_case']) && $alter['path_case'] != 'none') { if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
@ -1266,16 +1299,16 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
} }
// If the path is empty do not build a link around the given text and return // If the path is empty do not build a link around the given text and return
// it as is. // it as is. http://www.example.com URLs will not have a $url['path'], so
// http://www.example.com URLs will not have a $url['path'], so check host as well. // check host as well.
if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) { if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
return $text; return $text;
} }
// If no scheme is provided in the $path, assign the default 'http://'. // If no scheme is provided in the $path, assign the default 'http://'.
// This allows a url of 'www.example.com' to be converted to 'http://www.example.com'. // This allows a url of 'www.example.com' to be converted to
// Only do this on for external URLs. // 'http://www.example.com'. Only do this on for external URLs.
if ($alter['external']){ if ($alter['external']) {
if (!isset($url['scheme'])) { if (!isset($url['scheme'])) {
// There is no scheme, add the default 'http://' to the $path. // There is no scheme, add the default 'http://' to the $path.
$path = "http://$path"; $path = "http://$path";
@ -1320,13 +1353,14 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
$options['attributes']['rel'] = $rel; $options['attributes']['rel'] = $rel;
} }
$target = check_plain(trim(strtr($alter['target'],$tokens))); $target = check_plain(trim(strtr($alter['target'], $tokens)));
if (!empty($target)) { if (!empty($target)) {
$options['attributes']['target'] = $target; $options['attributes']['target'] = $target;
} }
// Allow the addition of arbitrary attributes to links. Additional attributes // Allow the addition of arbitrary attributes to links. Additional
// currently can only be altered in preprocessors and not within the UI. // attributes currently can only be altered in preprocessors and not within
// the UI.
if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) { if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
foreach ($alter['link_attributes'] as $key => $attribute) { foreach ($alter['link_attributes'] as $key => $attribute) {
if (!isset($options['attributes'][$key])) { if (!isset($options['attributes'][$key])) {
@ -1375,11 +1409,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Get the 'render' tokens to use for advanced rendering. * Get the 'render' tokens to use for advanced rendering.
* *
* This runs through all of the fields and arguments that * This runs through all of the fields and arguments that are available and
* are available and gets their values. This will then be * gets their values. This will then be used in one giant str_replace().
* used in one giant str_replace().
*/ */
function get_render_tokens($item) { public function get_render_tokens($item) {
$tokens = array(); $tokens = array();
if (!empty($this->view->build_info['substitutions'])) { if (!empty($this->view->build_info['substitutions'])) {
$tokens = $this->view->build_info['substitutions']; $tokens = $this->view->build_info['substitutions'];
@ -1391,9 +1424,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
$tokens[$token] = ''; $tokens[$token] = '';
} }
// Use strip tags as there should never be HTML in the path. // Use strip tags as there should never be HTML in the path. However, we
// However, we need to preserve special characters like " that // need to preserve special characters like " that were removed by
// were removed by check_plain(). // check_plain().
$tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : ''; $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
} }
@ -1450,27 +1483,28 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* '%bar_b_c' => 'value' * '%bar_b_c' => 'value'
* ); * );
* *
* @param $array * @param array $array
* An array of values. * An array of values.
* * @param array $parent_keys
* @param $parent_keys
* An array of parent keys. This will represent the array depth. * An array of parent keys. This will represent the array depth.
* *
* @return * @return array
* An array of available tokens, with nested keys representative of the array structure. * An array of available tokens, with nested keys representative of the
* array structure.
*/ */
function get_token_values_recursive(array $array, array $parent_keys = array()) { public function get_token_values_recursive(array $array, array $parent_keys = array()) {
$tokens = array(); $tokens = array();
foreach ($array as $param => $val) { foreach ($array as $param => $val) {
if (is_array($val)) { if (is_array($val)) {
// Copy parent_keys array, so we don't afect other elements of this iteration. // Copy parent_keys array, so we don't afect other elements of this
$child_parent_keys = $parent_keys; // iteration.
$child_parent_keys[] = $param; $child_parent_keys = $parent_keys;
// Get the child tokens. $child_parent_keys[] = $param;
$child_tokens = $this->get_token_values_recursive($val, $child_parent_keys); // Get the child tokens.
// Add them to the current tokens array. $child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
$tokens += $child_tokens; // Add them to the current tokens array.
$tokens += $child_tokens;
} }
else { else {
// Create a token key based on array element structure. // Create a token key based on array element structure.
@ -1485,50 +1519,57 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
/** /**
* Add any special tokens this field might use for itself. * Add any special tokens this field might use for itself.
* *
* This method is intended to be overridden by items that generate * This method is intended to be overridden by items that generate fields as a
* fields as a list. For example, the field that displays all terms * list. For example, the field that displays all terms on a node might have
* on a node might have tokens for the tid and the term. * tokens for the tid and the term.
* *
* By convention, tokens should follow the format of [token-subtoken] * By convention, tokens should follow the format of [token-subtoken] where
* where token is the field ID and subtoken is the field. If the * token is the field ID and subtoken is the field. If the field ID is terms,
* field ID is terms, then the tokens might be [terms-tid] and [terms-name]. * then the tokens might be [terms-tid] and [terms-name].
*/ */
function add_self_tokens(&$tokens, $item) { } public function add_self_tokens(&$tokens, $item) {
}
/** /**
* Document any special tokens this field might use for itself. * Document any special tokens this field might use for itself.
* *
* @see add_self_tokens() * @see add_self_tokens()
*/ */
function document_self_tokens(&$tokens) { } public function document_self_tokens(&$tokens) {
}
/** /**
* Call out to the theme() function, which probably just calls render() but * Call out to the theme() function.
* allows sites to override output fairly easily. *
* It probably just calls render() but allows sites to override output fairly
* easily.
*/ */
function theme($values) { public function theme($values) {
return theme($this->theme_functions(), return theme($this->theme_functions(),
array( array(
'view' => $this->view, 'view' => $this->view,
'field' => $this, 'field' => $this,
'row' => $values 'row' => $values,
)); ));
} }
function theme_functions() { /**
* Build a list of suitable theme functions for this view.
*/
public function theme_functions() {
$themes = array(); $themes = array();
$hook = 'views_view_field'; $hook = 'views_view_field';
$display = $this->view->display[$this->view->current_display]; $display = $this->view->display[$this->view->current_display];
if (!empty($display)) { if (!empty($display)) {
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id']; $themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id; $themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
$themes[] = $hook . '__' . $display->id . '__' . $this->options['id']; $themes[] = $hook . '__' . $display->id . '__' . $this->options['id'];
$themes[] = $hook . '__' . $display->id; $themes[] = $hook . '__' . $display->id;
if ($display->id != $display->display_plugin) { 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 . '__' . $this->options['id'];
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin; $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
$themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id']; $themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id'];
$themes[] = $hook . '__' . $display->display_plugin; $themes[] = $hook . '__' . $display->display_plugin;
} }
@ -1541,9 +1582,13 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
return $themes; return $themes;
} }
function ui_name($short = FALSE) { /**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return $this->get_field(parent::ui_name($short)); return $this->get_field(parent::ui_name($short));
} }
} }
/** /**
@ -1552,22 +1597,44 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_broken extends views_handler_field { class views_handler_field_broken extends views_handler_field {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query($group_by = FALSE) { /* No query to run */ } * {@inheritdoc}
function options_form(&$form, &$form_state) { */
public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item description">' . 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.') . '</div>', '#markup' => '<div class="form-item description">' . 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.') . '</div>',
); );
} }
/** /**
* Determine if the handler is considered 'broken' * {@inheritdoc}
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }
/** /**
@ -1576,7 +1643,11 @@ class views_handler_field_broken extends views_handler_field {
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_file_size extends views_handler_field { class views_handler_field_file_size extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['file_size_display'] = array('default' => 'formatted'); $options['file_size_display'] = array('default' => 'formatted');
@ -1584,7 +1655,10 @@ class views_handler_field_file_size extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['file_size_display'] = array( $form['file_size_display'] = array(
'#title' => t('File size display'), '#title' => t('File size display'),
@ -1596,7 +1670,10 @@ class views_handler_field_file_size extends views_handler_field {
); );
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
if ($value) { if ($value) {
switch ($this->options['file_size_display']) { switch ($this->options['file_size_display']) {
@ -1611,6 +1688,7 @@ class views_handler_field_file_size extends views_handler_field {
return ''; return '';
} }
} }
} }
/** /**
@ -1619,10 +1697,15 @@ class views_handler_field_file_size extends views_handler_field {
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_xss extends views_handler_field { class views_handler_field_xss extends views_handler_field {
function render($values) {
/**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->sanitize_value($value, 'xss'); return $this->sanitize_value($value, 'xss');
} }
} }
/** /**

View File

@ -11,18 +11,22 @@
* Allows for display of true/false, yes/no, on/off, enabled/disabled. * Allows for display of true/false, yes/no, on/off, enabled/disabled.
* *
* Definition terms: * Definition terms:
* - output formats: An array where the first entry is displayed on boolean true * - output formats: An array where the first entry is displayed on boolean true
* and the second is displayed on boolean false. An example for sticky is: * and the second is displayed on boolean false. An example for sticky is:
* @code * @code
* 'output formats' => array( * 'output formats' => array(
* 'sticky' => array(t('Sticky'), ''), * 'sticky' => array(t('Sticky'), ''),
* ), * ),
* @endcode * @endcode
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_boolean extends views_handler_field { class views_handler_field_boolean extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['type'] = array('default' => 'yes-no'); $options['type'] = array('default' => 'yes-no');
$options['type_custom_true'] = array('default' => '', 'translatable' => TRUE); $options['type_custom_true'] = array('default' => '', 'translatable' => TRUE);
@ -32,7 +36,10 @@ class views_handler_field_boolean extends views_handler_field {
return $options; return $options;
} }
function init(&$view, &$options) { /**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
$default_formats = array( $default_formats = array(
@ -48,7 +55,10 @@ class views_handler_field_boolean extends views_handler_field {
$this->formats = array_merge($default_formats, $output_formats, $custom_format); $this->formats = array_merge($default_formats, $output_formats, $custom_format);
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
foreach ($this->formats as $key => $item) { foreach ($this->formats as $key => $item) {
$options[$key] = implode('/', $item); $options[$key] = implode('/', $item);
} }
@ -91,7 +101,10 @@ class views_handler_field_boolean extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
if (!empty($this->options['not'])) { if (!empty($this->options['not'])) {
$value = !$value; $value = !$value;
@ -100,11 +113,12 @@ class views_handler_field_boolean extends views_handler_field {
if ($this->options['type'] == 'custom') { if ($this->options['type'] == 'custom') {
return $value ? filter_xss_admin($this->options['type_custom_true']) : filter_xss_admin($this->options['type_custom_false']); return $value ? filter_xss_admin($this->options['type_custom_true']) : filter_xss_admin($this->options['type_custom_false']);
} }
else if (isset($this->formats[$this->options['type']])) { elseif (isset($this->formats[$this->options['type']])) {
return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1]; return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1];
} }
else { else {
return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1]; return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1];
} }
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_contextual_links extends views_handler_field_links { class views_handler_field_contextual_links extends views_handler_field_links {
function pre_render(&$values) {
/**
* {@inheritdoc}
*/
public function pre_render(&$values) {
// Add a row plugin css class for the contextual link. // Add a row plugin css class for the contextual link.
$class = 'contextual-links-region'; $class = 'contextual-links-region';
if (!empty($this->view->style_plugin->options['row_class'])) { if (!empty($this->view->style_plugin->options['row_class'])) {
@ -22,7 +26,10 @@ class views_handler_field_contextual_links extends views_handler_field_links {
} }
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['fields']['#description'] = t('Fields to be included as contextual links.'); $form['fields']['#description'] = t('Fields to be included as contextual links.');
@ -32,7 +39,7 @@ class views_handler_field_contextual_links extends views_handler_field_links {
/** /**
* Render the contextual fields. * Render the contextual fields.
*/ */
function render($values) { public function render($values) {
$links = $this->get_links(); $links = $this->get_links();
if (!empty($links)) { if (!empty($links)) {
$build = array( $build = array(
@ -52,4 +59,5 @@ class views_handler_field_contextual_links extends views_handler_field_links {
return ''; return '';
} }
} }
} }

View File

@ -11,14 +11,21 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_counter extends views_handler_field { class views_handler_field_counter extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['counter_start'] = array('default' => 1); $options['counter_start'] = array('default' => 1);
$options['reverse'] = array('default' => FALSE); $options['reverse'] = array('default' => FALSE);
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['counter_start'] = array( $form['counter_start'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Starting value'), '#title' => t('Starting value'),
@ -37,24 +44,31 @@ class views_handler_field_counter extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function query() { /**
// do nothing -- to override the parent query. * {@inheritdoc}
*/
public function query() {
// Do nothing -- to override the parent query.
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$reverse = empty($this->options['reverse']) ? 1 : -1; $reverse = empty($this->options['reverse']) ? 1 : -1;
// Note: 1 is subtracted from the counter start value below because the // Note: 1 is subtracted from the counter start value below because the
// counter value is incremented by 1 at the end of this function. // counter value is incremented by 1 at the end of this function.
$counter_start = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] : 0; $counter_start = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] : 0;
$count = ($reverse == -1) ? count($this->view->result) + $counter_start : $counter_start -1; $count = ($reverse == -1) ? count($this->view->result) + $counter_start : $counter_start - 1;
$pager = $this->view->query->pager; $pager = $this->view->query->pager;
// Get the base count of the pager. // Get the base count of the pager.
if ($pager->use_pager()) { if ($pager->use_pager()) {
if ($reverse == -1) { if ($reverse == -1) {
$count = ($pager->total_items + $counter_start - ($pager->get_current_page() * $pager->get_items_per_page()) + $pager->get_offset()); $count = ($pager->total_items + $counter_start - ($pager->get_current_page() * $pager->get_items_per_page()) + $pager->get_offset());
} else { }
else {
$count += (($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset())) * $reverse; $count += (($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset())) * $reverse;
} }
} }
@ -63,4 +77,5 @@ class views_handler_field_counter extends views_handler_field {
return $count; return $count;
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_ctools_dropdown extends views_handler_field_links { class views_handler_field_ctools_dropdown extends views_handler_field_links {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['views_admin_css'] = array('default' => TRUE, 'bool' => TRUE); $options['views_admin_css'] = array('default' => TRUE, 'bool' => TRUE);
@ -19,7 +23,10 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['fields']['#description'] = t('Fields to be included as ctools dropdown button.'); $form['fields']['#description'] = t('Fields to be included as ctools dropdown button.');
$form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing a link action.'); $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing a link action.');
@ -35,7 +42,7 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
/** /**
* Render the dropdown button. * Render the dropdown button.
*/ */
function render($values) { public function render($values) {
static $added_admin_css; static $added_admin_css;
$links = $this->get_links(); $links = $this->get_links();
@ -46,10 +53,20 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
$added_admin_css = TRUE; $added_admin_css = TRUE;
} }
return theme('links__ctools_dropbutton', array('links' => $links, 'attributes' => array('class' => array('links', 'inline')))); $vars = array(
'links' => $links,
'attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
return theme('links__ctools_dropbutton', $vars);
} }
else { else {
return ''; return '';
} }
} }
} }

View File

@ -11,11 +11,18 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_custom extends views_handler_field { class views_handler_field_custom extends views_handler_field {
function query() {
// do nothing -- to override the parent query. /**
* {@inheritdoc}
*/
public function query() {
// Do nothing -- to override the parent query.
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
// Override the alter text option to always alter the text. // Override the alter text option to always alter the text.
@ -24,10 +31,13 @@ class views_handler_field_custom extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Remove the checkbox // Remove the checkbox.
unset($form['alter']['alter_text']); unset($form['alter']['alter_text']);
unset($form['alter']['text']['#dependency']); unset($form['alter']['text']['#dependency']);
unset($form['alter']['text']['#process']); unset($form['alter']['text']['#process']);
@ -36,10 +46,14 @@ class views_handler_field_custom extends views_handler_field {
$form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text'; $form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text';
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
// Return the text, so the code never thinks the value is empty. // Return the text, so the code never thinks the value is empty.
return $this->options['alter']['text']; return $this->options['alter']['text'];
} }
} }
/** /**

View File

@ -11,7 +11,11 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_date extends views_handler_field { class views_handler_field_date extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['date_format'] = array('default' => 'small'); $options['date_format'] = array('default' => 'small');
@ -23,8 +27,10 @@ class views_handler_field_date extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$date_formats = array(); $date_formats = array();
$date_types = system_get_date_types(); $date_types = system_get_date_types();
foreach ($date_types as $key => $value) { foreach ($date_types as $key => $value) {
@ -52,66 +58,106 @@ class views_handler_field_date extends views_handler_field {
'#title' => t('Custom date format'), '#title' => t('Custom date format'),
'#description' => t('If "Custom", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')), '#description' => t('If "Custom", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
'#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '', '#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
'#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span')), '#dependency' => array(
'edit-options-date-format' => $this->supported_date_types(),
),
); );
$form['second_date_format'] = array( $form['second_date_format'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Second date format'), '#title' => t('Second date format'),
'#options' => $date_formats + array( '#options' => $date_formats + array(
'custom' => t('Custom'), 'custom' => t('Custom'),
), ),
'#description' => t('The date format which will be used for rendering dates other than today.'), '#description' => t('The date format which will be used for rendering dates other than today.'),
'#default_value' => isset($this->options['second_date_format']) ? $this->options['second_date_format'] : 'small', '#default_value' => isset($this->options['second_date_format']) ? $this->options['second_date_format'] : 'small',
'#dependency' => array('edit-options-date-format' => array('today time ago')), '#dependency' => array(
); 'edit-options-date-format' => array('today time ago'),
$form['second_date_format_custom'] = array( ),
'#type' => 'textfield', );
'#title' => t('Custom date format of second date'), $form['second_date_format_custom'] = array(
'#description' => t('If "Custom" is selected in "Second date format", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')), '#type' => 'textfield',
'#default_value' => isset($this->options['second_date_format_custom']) ? $this->options['second_date_format_custom'] : '', '#title' => t('Custom date format of second date'),
// We have to use states instead of ctools dependency because dependency '#description' => t('If "Custom" is selected in "Second date format", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
// doesn't handle multiple conditions. '#default_value' => isset($this->options['second_date_format_custom']) ? $this->options['second_date_format_custom'] : '',
'#states' => array( // We have to use states instead of ctools dependency because dependency
'visible' => array( // doesn't handle multiple conditions.
'#edit-options-date-format' => array('value' => 'today time ago'), '#states' => array(
'#edit-options-second-date-format' => array('value' => 'custom'), 'visible' => array(
), '#edit-options-date-format' => array('value' => 'today time ago'),
), '#edit-options-second-date-format' => array('value' => 'custom'),
// We have to use ctools dependency too because states doesn't add the ),
// correct left margin to the element's wrapper. ),
'#dependency' => array( // We have to use ctools dependency too because states doesn't add the
// This condition is handled by form API's states. // correct left margin to the element's wrapper.
// 'edit-options-date-format' => array('today time ago'), '#dependency' => array(
'edit-options-second-date-format' => array('custom'), // This condition is handled by form API's states.
), // 'edit-options-date-format' => array('today time ago'),
); 'edit-options-second-date-format' => array('custom'),
),
);
$form['timezone'] = array( $form['timezone'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Timezone'), '#title' => t('Timezone'),
'#description' => t('Timezone to be used for date output.'), '#description' => t('Timezone to be used for date output.'),
'#options' => array('' => t('- Default site/user timezone -')) + system_time_zones(FALSE), '#options' => array(
'' => t('- Default site/user timezone -'),
) + system_time_zones(FALSE),
'#default_value' => $this->options['timezone'], '#default_value' => $this->options['timezone'],
'#dependency' => array('edit-options-date-format' => array_merge(array('custom'), array_keys($date_formats))), '#dependency' => array(
'edit-options-date-format' => array_merge(array('custom'), array_keys($date_formats)),
),
); );
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render($values) { /**
* Provide a list of all of the supported standard date types.
*
* @return array
* The list of supported formats.
*/
private function supported_date_types() {
return array(
'custom',
'raw time ago',
'time ago',
'today time ago',
'raw time hence',
'time hence',
'raw time span',
'time span',
'raw time span',
'inverse time span',
'time span',
);
}
/**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
$format = $this->options['date_format']; $format = $this->options['date_format'];
if (in_array($format, array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) { if (in_array($format, $this->supported_date_types())) {
$custom_format = $this->options['custom_date_format']; $custom_format = $this->options['custom_date_format'];
} }
if ($value) { if ($value) {
$timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL; $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
$time_diff = REQUEST_TIME - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence) // Will be positive for a datetime in the past (ago), and negative for a
// datetime in the future (hence).
$time_diff = REQUEST_TIME - $value;
switch ($format) { switch ($format) {
case 'raw time ago': case 'raw time ago':
return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2); return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
case 'time ago': case 'time ago':
return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2))); $t_args = array(
'%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2),
);
return t('%time ago', $t_args);
case 'today time ago': case 'today time ago':
$second_format = $this->options['second_date_format']; $second_format = $this->options['second_date_format'];
$second_custom_format = $this->options['second_date_format_custom']; $second_custom_format = $this->options['second_date_format_custom'];
@ -127,24 +173,32 @@ class views_handler_field_date extends views_handler_field {
else { else {
return format_date($value, $this->options['second_date_format'], '', $timezone); return format_date($value, $this->options['second_date_format'], '', $timezone);
} }
case 'raw time hence': case 'raw time hence':
return format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2); return format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2);
case 'time hence': case 'time hence':
return t('%time hence', array('%time' => format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2))); return t('%time hence', array('%time' => format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2)));
case 'raw time span': case 'raw time span':
return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2); return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
case 'inverse time span': case 'inverse time span':
return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2); return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
case 'time span': 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))); 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': case 'custom':
if ($custom_format == 'r') { if ($custom_format == 'r') {
return format_date($value, $format, $custom_format, $timezone, 'en'); return format_date($value, $format, $custom_format, $timezone, 'en');
} }
return format_date($value, $format, $custom_format, $timezone); return format_date($value, $format, $custom_format, $timezone);
default: default:
return format_date($value, $format, '', $timezone); return format_date($value, $format, '', $timezone);
} }
} }
} }
} }

View File

@ -11,7 +11,7 @@
* Fields based upon this handler work with all query-backends if the tables * Fields based upon this handler work with all query-backends if the tables
* used by the query backend have an 'entity type' specified. In order to * used by the query backend have an 'entity type' specified. In order to
* make fields based upon this handler automatically available to all compatible * make fields based upon this handler automatically available to all compatible
* query backends, the views field can be defined in the table * query backends, the views field can be defined in the table.
* @code views_entity_{ENTITY_TYPE} @endcode. * @code views_entity_{ENTITY_TYPE} @endcode.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
@ -47,7 +47,7 @@ class views_handler_field_entity extends views_handler_field {
/** /**
* Overriden to add the field for the entity id. * Overriden to add the field for the entity id.
*/ */
function query() { public function query() {
$this->table_alias = $base_table = $this->view->base_table; $this->table_alias = $base_table = $this->view->base_table;
$this->base_field = $this->view->base_field; $this->base_field = $this->view->base_field;
@ -75,16 +75,16 @@ class views_handler_field_entity extends views_handler_field {
/** /**
* Load the entities for all rows that are about to be displayed. * Load the entities for all rows that are about to be displayed.
*/ */
function pre_render(&$values) { public function pre_render(&$values) {
if (!empty($values)) { if (!empty($values)) {
list($this->entity_type, $this->entities) = $this->query->get_result_entities($values, !empty($this->relationship) ? $this->relationship : NULL, $this->field_alias); list($this->entity_type, $this->entities) = $this->query->get_result_entities($values, !empty($this->relationship) ? $this->relationship : NULL, $this->field_alias);
} }
} }
/** /**
* Overridden to return the entity object, or a certain property of the entity. * Return the entity object or a certain property of the entity.
*/ */
function get_value($values, $field = NULL) { public function get_value($values, $field = NULL) {
if (isset($this->entities[$this->view->row_index])) { if (isset($this->entities[$this->view->row_index])) {
$entity = $this->entities[$this->view->row_index]; $entity = $this->entities[$this->view->row_index];
// Support to get a certain part of the entity. // Support to get a certain part of the entity.
@ -101,4 +101,5 @@ class views_handler_field_entity extends views_handler_field {
} }
return FALSE; return FALSE;
} }
} }

View File

@ -13,9 +13,9 @@
class views_handler_field_links extends views_handler_field { class views_handler_field_links extends views_handler_field {
/** /**
* Overrides views_handler_field::option_definition(). * {@inheritdoc}
*/ */
function option_definition() { public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['fields'] = array('default' => array()); $options['fields'] = array('default' => array());
@ -26,9 +26,9 @@ class views_handler_field_links extends views_handler_field {
} }
/** /**
* Overrides views_handler_field::options_form(). * {@inheritdoc}
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$all_fields = $this->view->display_handler->get_field_labels(); $all_fields = $this->view->display_handler->get_field_labels();
@ -59,9 +59,9 @@ class views_handler_field_links extends views_handler_field {
} }
/** /**
* Overrides views_handler_field::options_form(). * {@inheritdoc}
*/ */
function options_submit(&$form, &$form_state) { public function options_submit(&$form, &$form_state) {
// Remove unselected options. // Remove unselected options.
$form_state['values']['options']['fields'] = array_filter($form_state['values']['options']['fields']); $form_state['values']['options']['fields'] = array_filter($form_state['values']['options']['fields']);
} }
@ -72,7 +72,7 @@ class views_handler_field_links extends views_handler_field {
* @return array * @return array
* The links which are used by the render function. * The links which are used by the render function.
*/ */
function get_links() { public function get_links() {
$links = array(); $links = array();
foreach ($this->options['fields'] as $field) { foreach ($this->options['fields'] as $field) {
if (empty($this->view->field[$field]->last_render_text)) { if (empty($this->view->field[$field]->last_render_text)) {
@ -121,7 +121,6 @@ class views_handler_field_links extends views_handler_field {
} }
// Omit tweaks of query, fragment, and link_class. // Omit tweaks of query, fragment, and link_class.
$alt = strtr($alter['alt'], $tokens); $alt = strtr($alter['alt'], $tokens);
if ($alt && $alt != $title) { if ($alt && $alt != $title) {
// Set the title attribute only if it improves accessibility. // Set the title attribute only if it improves accessibility.
@ -148,8 +147,9 @@ class views_handler_field_links extends views_handler_field {
} }
/** /**
* Overrides views_handler_field::query(). * {@inheritdoc}
*/ */
function query() { } public function query() {
}
} }

View File

@ -10,16 +10,21 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
* *
* Definition items: * Definition items:
* - options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used. * - options callback: The function to call in order to generate the value
* options. If omitted, the options 'Yes' and 'No' will be used.
* - options arguments: An array of arguments to pass to the options callback. * - options arguments: An array of arguments to pass to the options callback.
*/ */
class views_handler_field_machine_name extends views_handler_field { class views_handler_field_machine_name extends views_handler_field {
/** /**
* @var array Stores the available options. * @var array Stores the available options.
*/ */
var $value_options; public $value_options;
function get_value_options() { /**
* {@inheritdoc}
*/
public function get_value_options() {
if (isset($this->value_options)) { if (isset($this->value_options)) {
return; return;
} }
@ -37,14 +42,20 @@ class views_handler_field_machine_name extends views_handler_field {
} }
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['machine_name'] = array('default' => FALSE, 'bool' => TRUE); $options['machine_name'] = array('default' => FALSE, 'bool' => TRUE);
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['machine_name'] = array( $form['machine_name'] = array(
@ -55,11 +66,17 @@ class views_handler_field_machine_name extends views_handler_field {
); );
} }
function pre_render(&$values) { /**
* {@inheritdoc}
*/
public function pre_render(&$values) {
$this->get_value_options(); $this->get_value_options();
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $values->{$this->field_alias}; $value = $values->{$this->field_alias};
if (!empty($this->options['machine_name']) || !isset($this->value_options[$value])) { if (!empty($this->options['machine_name']) || !isset($this->value_options[$value])) {
$result = check_plain($value); $result = check_plain($value);
@ -70,4 +87,5 @@ class views_handler_field_machine_name extends views_handler_field {
return $result; return $result;
} }
} }

View File

@ -10,17 +10,18 @@
* format field. * format field.
* *
* - format: (REQUIRED) Either a string format id to use for this field or an * - format: (REQUIRED) Either a string format id to use for this field or an
* array('field' => {$field}) where $field is the field in this table * array('field' => {$field}) where $field is the field in this table used to
* used to control the format such as the 'format' field in the node, * control the format such as the 'format' field in the node, which goes with
* which goes with the 'body' field. * the 'body' field.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_markup extends views_handler_field { class views_handler_field_markup extends views_handler_field {
/** /**
* Constructor; calls to base object constructor. * {@inheritdoc}
*/ */
function construct() { public function construct() {
parent::construct(); parent::construct();
$this->format = $this->definition['format']; $this->format = $this->definition['format'];
@ -31,7 +32,10 @@ class views_handler_field_markup extends views_handler_field {
} }
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
if (is_array($this->format)) { if (is_array($this->format)) {
$format = $this->get_value($values, 'format'); $format = $this->get_value($values, 'format');
@ -45,7 +49,10 @@ class views_handler_field_markup extends views_handler_field {
} }
} }
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) { /**
* {@inheritdoc}
*/
public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
if ($inline) { if ($inline) {
return 'span'; return 'span';
} }
@ -56,4 +63,5 @@ class views_handler_field_markup extends views_handler_field {
return 'div'; return 'div';
} }
} }

View File

@ -15,14 +15,21 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_math extends views_handler_field_numeric { class views_handler_field_math extends views_handler_field_numeric {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['expression'] = array('default' => ''); $options['expression'] = array('default' => '');
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['expression'] = array( $form['expression'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Expression'), '#title' => t('Expression'),
@ -30,17 +37,20 @@ class views_handler_field_math extends views_handler_field_numeric {
'#default_value' => $this->options['expression'], '#default_value' => $this->options['expression'],
); );
// Create a place for the help // Create a place for the help.
$form['expression_help'] = array(); $form['expression_help'] = array();
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Then move the existing help: // Then move the existing help.
$form['expression_help'] = $form['alter']['help']; $form['expression_help'] = $form['alter']['help'];
unset($form['expression_help']['#dependency']); unset($form['expression_help']['#dependency']);
unset($form['alter']['help']); unset($form['alter']['help']);
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
ctools_include('math-expr'); ctools_include('math-expr');
$tokens = array_map('floatval', $this->get_render_tokens(array())); $tokens = array_map('floatval', $this->get_render_tokens(array()));
$value = strtr($this->options['expression'], $tokens); $value = strtr($this->options['expression'], $tokens);
@ -80,5 +90,10 @@ class views_handler_field_math extends views_handler_field_numeric {
return $this->sanitize_value($this->options['prefix'] . $value . $this->options['suffix']); return $this->sanitize_value($this->options['prefix'] . $value . $this->options['suffix']);
} }
function query() { } /**
* {@inheritdoc}
*/
public function query() {
}
} }

View File

@ -6,16 +6,20 @@
*/ */
/** /**
* Render a field as a numeric value * Render a field as a numeric value.
* *
* Definition terms: * Definition terms:
* - float: If true this field contains a decimal value. If unset this field * - float: If true this field contains a decimal value. If unset this field
* will be assumed to be integer. * will be assumed to be integer.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_numeric extends views_handler_field { class views_handler_field_numeric extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['set_precision'] = array('default' => FALSE, 'bool' => TRUE); $options['set_precision'] = array('default' => FALSE, 'bool' => TRUE);
@ -31,7 +35,10 @@ class views_handler_field_numeric extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
if (!empty($this->definition['float'])) { if (!empty($this->definition['float'])) {
$form['set_precision'] = array( $form['set_precision'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
@ -105,7 +112,10 @@ class views_handler_field_numeric extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
// Hiding should happen before rounding or adding prefix/suffix. // Hiding should happen before rounding or adding prefix/suffix.
@ -135,4 +145,5 @@ class views_handler_field_numeric extends views_handler_field {
. $this->sanitize_value($value) . $this->sanitize_value($value)
. $this->sanitize_value($this->options['suffix'], 'xss'); . $this->sanitize_value($this->options['suffix'], 'xss');
} }
} }

View File

@ -16,17 +16,22 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_prerender_list extends views_handler_field { class views_handler_field_prerender_list extends views_handler_field {
/** /**
* Stores all items which are used to render the items. * Stores all items which are used to render the items.
*
* It should be keyed first by the id of the base table, for example nid. * It should be keyed first by the id of the base table, for example nid.
* The second key is the id of the thing which is displayed multiple times * The second key is the id of the thing which is displayed multiple times
* per row, for example the tid. * per row, for example the tid.
* *
* @var array * @var array
*/ */
var $items = array(); public $items = array();
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['type'] = array('default' => 'separator'); $options['type'] = array('default' => 'separator');
@ -35,7 +40,10 @@ class views_handler_field_prerender_list extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['type'] = array( $form['type'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Display type'), '#title' => t('Display type'),
@ -63,7 +71,7 @@ class views_handler_field_prerender_list extends views_handler_field {
* yet or won't update their prerender list fields. If a render_item method * yet or won't update their prerender list fields. If a render_item method
* exists, this will not get used by advanced_render. * exists, this will not get used by advanced_render.
*/ */
function render($values) { public function render($values) {
$field = $this->get_value($values); $field = $this->get_value($values);
if (!empty($this->items[$field])) { if (!empty($this->items[$field])) {
if ($this->options['type'] == 'separator') { if ($this->options['type'] == 'separator') {
@ -74,7 +82,7 @@ class views_handler_field_prerender_list extends views_handler_field {
array( array(
'items' => $this->items[$field], 'items' => $this->items[$field],
'title' => NULL, 'title' => NULL,
'type' => $this->options['type'] 'type' => $this->options['type'],
)); ));
} }
} }
@ -86,7 +94,7 @@ class views_handler_field_prerender_list extends views_handler_field {
* When using advanced render, each possible item in the list is rendered * When using advanced render, each possible item in the list is rendered
* individually. Then the items are all pasted together. * individually. Then the items are all pasted together.
*/ */
function render_items($items) { public function render_items($items) {
if (!empty($items)) { if (!empty($items)) {
if ($this->options['type'] == 'separator') { if ($this->options['type'] == 'separator') {
return implode($this->sanitize_value($this->options['separator'], 'xss_admin'), $items); return implode($this->sanitize_value($this->options['separator'], 'xss_admin'), $items);
@ -96,7 +104,7 @@ class views_handler_field_prerender_list extends views_handler_field {
array( array(
'items' => $items, 'items' => $items,
'title' => NULL, 'title' => NULL,
'type' => $this->options['type'] 'type' => $this->options['type'],
)); ));
} }
} }
@ -105,14 +113,18 @@ class views_handler_field_prerender_list extends views_handler_field {
/** /**
* Return an array of items for the field. * Return an array of items for the field.
* *
* Items should be stored in the result array, if possible, as an array * Items should be stored in the result array, if possible, as an array with
* with 'value' as the actual displayable value of the item, plus * 'value' as the actual displayable value of the item, plus any items that
* any items that might be found in the 'alter' options array for * might be found in the 'alter' options array for creating links, such as
* creating links, such as 'path', 'fragment', 'query' etc, such a thing * 'path', 'fragment', 'query' etc, such a thing is to be made. Additionally,
* is to be made. Additionally, items that might be turned into tokens * items that might be turned into tokens should also be in this array.
* should also be in this array. *
* @param mixed $values
*
* @return array
* The items.
*/ */
function get_items($values) { public function get_items($values) {
// Only the parent get_value returns a single field. // Only the parent get_value returns a single field.
$field = parent::get_value($values); $field = parent::get_value($values);
if (!empty($this->items[$field])) { if (!empty($this->items[$field])) {
@ -125,14 +137,14 @@ class views_handler_field_prerender_list extends views_handler_field {
/** /**
* Get the value that's supposed to be rendered. * Get the value that's supposed to be rendered.
* *
* @param $values * @param object $values
* An object containing all retrieved values. * An object containing all retrieved values.
* @param $field * @param string $field
* Optional name of the field where the value is stored. * Optional name of the field where the value is stored.
* @param $raw * @param bool $raw
* Use the raw data and not the data defined in pre_render * Use the raw data and not the data defined in pre_render
*/ */
function get_value($values, $field = NULL, $raw = FALSE) { public function get_value($values, $field = NULL, $raw = FALSE) {
if ($raw) { if ($raw) {
return parent::get_value($values, $field); return parent::get_value($values, $field);
} }
@ -149,10 +161,14 @@ class views_handler_field_prerender_list extends views_handler_field {
* *
* By default, advanced rendering will NOT be allowed if the class * By default, advanced rendering will NOT be allowed if the class
* inheriting from this does not implement a 'render_items' method. * inheriting from this does not implement a 'render_items' method.
*
* @return bool
* Whether or not the the render method exists.
*/ */
function allow_advanced_render() { public function allow_advanced_render() {
// Note that the advanced render bits also use the presence of // Note that the advanced render bits also use the presence of
// this method to determine if it needs to render items as a list. // this method to determine if it needs to render items as a list.
return method_exists($this, 'render_item'); return method_exists($this, 'render_item');
} }
} }

View File

@ -12,15 +12,20 @@
*/ */
class views_handler_field_serialized extends views_handler_field { class views_handler_field_serialized extends views_handler_field {
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['format'] = array('default' => 'unserialized'); $options['format'] = array('default' => 'unserialized');
$options['key'] = array('default' => ''); $options['key'] = array('default' => '');
return $options; return $options;
} }
/**
function options_form(&$form, &$form_state) { * {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['format'] = array( $form['format'] = array(
@ -42,14 +47,20 @@ class views_handler_field_serialized extends views_handler_field {
); );
} }
function options_validate(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_validate(&$form, &$form_state) {
// Require a key if the format is key. // Require a key if the format is key.
if ($form_state['values']['options']['format'] == 'key' && $form_state['values']['options']['key'] == '') { if ($form_state['values']['options']['format'] == 'key' && $form_state['values']['options']['key'] == '') {
form_error($form['key'], t('You have to enter a key if you want to display a key of the data.')); form_error($form['key'], t('You have to enter a key if you want to display a key of the data.'));
} }
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $values->{$this->field_alias}; $value = $values->{$this->field_alias};
if ($this->options['format'] == 'unserialized') { if ($this->options['format'] == 'unserialized') {
@ -62,4 +73,5 @@ class views_handler_field_serialized extends views_handler_field {
return $value; return $value;
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_time_interval extends views_handler_field { class views_handler_field_time_interval extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['granularity'] = array('default' => 2); $options['granularity'] = array('default' => 2);
@ -19,7 +23,10 @@ class views_handler_field_time_interval extends views_handler_field {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['granularity'] = array( $form['granularity'] = array(
@ -30,8 +37,12 @@ class views_handler_field_time_interval extends views_handler_field {
); );
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $values->{$this->field_alias}; $value = $values->{$this->field_alias};
return format_interval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2); return format_interval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
} }
} }

View File

@ -6,12 +6,16 @@
*/ */
/** /**
* Field handler to provide simple renderer that turns a URL into a clickable link. * Field handler that turns a URL into a clickable link.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_url extends views_handler_field { class views_handler_field_url extends views_handler_field {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE); $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
@ -22,7 +26,7 @@ class views_handler_field_url extends views_handler_field {
/** /**
* Provide link to the page being visited. * Provide link to the page being visited.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
$form['display_as_link'] = array( $form['display_as_link'] = array(
'#title' => t('Display as link'), '#title' => t('Display as link'),
'#type' => 'checkbox', '#type' => 'checkbox',
@ -31,7 +35,10 @@ class views_handler_field_url extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
if (!empty($this->options['display_as_link'])) { if (!empty($this->options['display_as_link'])) {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
@ -43,4 +50,5 @@ class views_handler_field_url extends views_handler_field {
return $this->sanitize_value($value, 'url'); return $this->sanitize_value($value, 'url');
} }
} }
} }

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* @todo. * Definitions of views_handler_filter and views_handler_filter_broken.
*/ */
/** /**
@ -32,39 +32,49 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter extends views_handler { class views_handler_filter extends views_handler {
/** /**
* Contains the actual value of the field,either configured in the views ui * Contains the actual value of the field,either configured in the views ui
* or entered in the exposed filters. * or entered in the exposed filters.
*
* @var mixed
*/ */
var $value = NULL; public $value = NULL;
/** /**
* Contains the operator which is used on the query. * Contains the operator which is used on the query.
*
* @var string
*/ */
var $operator = '='; public $operator = '=';
/** /**
* Contains the information of the selected item in a gruped filter. * Contains the information of the selected item in a gruped filter.
*
* @var array|null
*/ */
var $group_info = NULL; public $group_info = NULL;
/** /**
* @var bool
* Disable the possibility to force a single value. * Disable the possibility to force a single value.
*
* @var bool
*/ */
var $always_multiple = FALSE; public $always_multiple = FALSE;
/** /**
* @var bool
* Disable the possibility to use operators. * Disable the possibility to use operators.
*
* @var bool
*/ */
var $no_operator = FALSE; public $no_operator = FALSE;
/** /**
* @var bool
* Disable the possibility to allow a exposed input to be optional. * Disable the possibility to allow a exposed input to be optional.
*
* @var bool
*/ */
var $always_required = FALSE; public $always_required = FALSE;
/** /**
* Provide some extra help to get the operator/value easier to use. * Provide some extra help to get the operator/value easier to use.
@ -72,7 +82,7 @@ class views_handler_filter extends views_handler {
* This likely has to be overridden by filters which are more complex * This likely has to be overridden by filters which are more complex
* than simple operator/value. * than simple operator/value.
*/ */
function init(&$view, &$options) { public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
$this->operator = $this->options['operator']; $this->operator = $this->options['operator'];
@ -107,7 +117,10 @@ class views_handler_filter extends views_handler {
} }
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['operator'] = array('default' => '='); $options['operator'] = array('default' => '=');
@ -160,39 +173,43 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Display the filter on the administrative summary * Display the filter on the administrative summary.
*/ */
function admin_summary() { public function admin_summary() {
return check_plain((string) $this->operator) . ' ' . check_plain((string) $this->value); return check_plain((string) $this->operator) . ' ' . check_plain((string) $this->value);
} }
/** /**
* Determine if a filter can be exposed. * Determine if a filter can be exposed.
*/ */
function can_expose() { return TRUE; } public function can_expose() {
return TRUE;
}
/** /**
* Determine if a filter can be converted into a group. * Determine if a filter can be converted into a group.
*
* Only exposed filters with operators available can be converted into groups. * Only exposed filters with operators available can be converted into groups.
*/ */
function can_build_group() { public function can_build_group() {
return $this->is_exposed() && (count($this->operator_options()) > 0); return $this->is_exposed() && (count($this->operator_options()) > 0);
} }
/** /**
* Returns TRUE if the exposed filter works like a grouped filter. * Returns TRUE if the exposed filter works like a grouped filter.
*/ */
function is_a_group() { public function is_a_group() {
return $this->is_exposed() && !empty($this->options['is_grouped']); return $this->is_exposed() && !empty($this->options['is_grouped']);
} }
/** /**
* Provide the basic form which calls through to subforms. * Provide the basic form which calls through to subforms.
*
* If overridden, it is best to call through to the parent, * If overridden, it is best to call through to the parent,
* or to at least make sure all of the functions in this form * or to at least make sure all of the functions in this form
* are called. * are called.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
if ($this->can_expose()) { if ($this->can_expose()) {
$this->show_expose_button($form, $form_state); $this->show_expose_button($form, $form_state);
@ -233,7 +250,7 @@ class views_handler_filter extends views_handler {
/** /**
* Simple validate handler * Simple validate handler
*/ */
function options_validate(&$form, &$form_state) { public function options_validate(&$form, &$form_state) {
$this->operator_validate($form, $form_state); $this->operator_validate($form, $form_state);
$this->value_validate($form, $form_state); $this->value_validate($form, $form_state);
if (!empty($this->options['exposed']) && !$this->is_a_group()) { if (!empty($this->options['exposed']) && !$this->is_a_group()) {
@ -245,11 +262,13 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Simple submit handler * Simple submit handler.
*/ */
function options_submit(&$form, &$form_state) { public function options_submit(&$form, &$form_state) {
unset($form_state['values']['expose_button']); // don't store this. // Don't store these.
unset($form_state['values']['group_button']); // don't store this. unset($form_state['values']['expose_button']);
unset($form_state['values']['group_button']);
if (!$this->is_a_group()) { if (!$this->is_a_group()) {
$this->operator_submit($form, $form_state); $this->operator_submit($form, $form_state);
$this->value_submit($form, $form_state); $this->value_submit($form, $form_state);
@ -265,7 +284,7 @@ class views_handler_filter extends views_handler {
/** /**
* Shortcut to display the operator form. * Shortcut to display the operator form.
*/ */
function show_operator_form(&$form, &$form_state) { public function show_operator_form(&$form, &$form_state) {
$this->operator_form($form, $form_state); $this->operator_form($form, $form_state);
$form['operator']['#prefix'] = '<div class="views-group-box views-left-30">'; $form['operator']['#prefix'] = '<div class="views-group-box views-left-30">';
$form['operator']['#suffix'] = '</div>'; $form['operator']['#suffix'] = '</div>';
@ -279,7 +298,7 @@ class views_handler_filter extends views_handler {
* *
* @see options_form() * @see options_form()
*/ */
function operator_form(&$form, &$form_state) { public function operator_form(&$form, &$form_state) {
$options = $this->operator_options(); $options = $this->operator_options();
if (!empty($options)) { if (!empty($options)) {
$form['operator'] = array( $form['operator'] = array(
@ -293,25 +312,31 @@ class views_handler_filter extends views_handler {
/** /**
* Provide a list of options for the default operator form. * Provide a list of options for the default operator form.
*
* Should be overridden by classes that don't override operator_form * Should be overridden by classes that don't override operator_form
*/ */
function operator_options() { return array(); } public function operator_options() {
return array();
}
/** /**
* Validate the operator form. * Validate the operator form.
*/ */
function operator_validate($form, &$form_state) { } public function operator_validate($form, &$form_state) {
}
/** /**
* Perform any necessary changes to the form values prior to storage. * Perform any necessary changes to the form values prior to storage.
*
* There is no need for this function to actually store the data. * There is no need for this function to actually store the data.
*/ */
function operator_submit($form, &$form_state) { } public function operator_submit($form, &$form_state) {
}
/** /**
* Shortcut to display the value form. * Shortcut to display the value form.
*/ */
function show_value_form(&$form, &$form_state) { public function show_value_form(&$form, &$form_state) {
$this->value_form($form, $form_state); $this->value_form($form, $form_state);
if (empty($this->no_operator)) { if (empty($this->no_operator)) {
$form['value']['#prefix'] = '<div class="views-group-box views-right-70">' . (isset($form['value']['#prefix']) ? $form['value']['#prefix'] : ''); $form['value']['#prefix'] = '<div class="views-group-box views-right-70">' . (isset($form['value']['#prefix']) ? $form['value']['#prefix'] : '');
@ -322,28 +347,33 @@ class views_handler_filter extends views_handler {
/** /**
* Options form subform for setting options. * Options form subform for setting options.
* *
* This should be overridden by all child classes and it must * This should be overridden by all child classes and it must define
* define $form['value'] * $form['value'].
* *
* @see options_form() * @see options_form()
*/ */
function value_form(&$form, &$form_state) { $form['value'] = array(); } public function value_form(&$form, &$form_state) {
$form['value'] = array();
}
/** /**
* Validate the options form. * Validate the options form.
*/ */
function value_validate($form, &$form_state) { } public function value_validate($form, &$form_state) {
}
/** /**
* Perform any necessary changes to the form values prior to storage. * Perform any necessary changes to the form values prior to storage.
*
* There is no need for this function to actually store the data. * There is no need for this function to actually store the data.
*/ */
function value_submit($form, &$form_state) { } public function value_submit($form, &$form_state) {
}
/** /**
* Shortcut to display the exposed options form. * Shortcut to display the exposed options form.
*/ */
function show_build_group_form(&$form, &$form_state) { public function show_build_group_form(&$form, &$form_state) {
if (empty($this->options['is_grouped'])) { if (empty($this->options['is_grouped'])) {
return; return;
} }
@ -366,8 +396,7 @@ class views_handler_filter extends views_handler {
/** /**
* Shortcut to display the build_group/hide button. * Shortcut to display the build_group/hide button.
*/ */
function show_build_group_button(&$form, &$form_state) { public function show_build_group_button(&$form, &$form_state) {
$form['group_button'] = array( $form['group_button'] = array(
'#prefix' => '<div class="views-grouped clearfix">', '#prefix' => '<div class="views-grouped clearfix">',
'#suffix' => '</div>', '#suffix' => '</div>',
@ -412,10 +441,11 @@ class views_handler_filter extends views_handler {
$form['group_button']['radios']['radios']['#default_value'] = 1; $form['group_button']['radios']['radios']['#default_value'] = 1;
} }
} }
/** /**
* Shortcut to display the expose/hide button. * Shortcut to display the expose/hide button.
*/ */
function show_expose_button(&$form, &$form_state) { public function show_expose_button(&$form, &$form_state) {
$form['expose_button'] = array( $form['expose_button'] = array(
'#prefix' => '<div class="views-expose clearfix">', '#prefix' => '<div class="views-expose clearfix">',
'#suffix' => '</div>', '#suffix' => '</div>',
@ -423,8 +453,8 @@ class views_handler_filter extends views_handler {
'#weight' => -200, '#weight' => -200,
); );
// Add a checkbox for JS users, which will have behavior attached to it // Add a checkbox for JS users, which will have behavior attached to it so
// so it can replace the button. // it can replace the button.
$form['expose_button']['checkbox'] = array( $form['expose_button']['checkbox'] = array(
'#theme_wrappers' => array('container'), '#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('js-only')), '#attributes' => array('class' => array('js-only')),
@ -466,7 +496,7 @@ class views_handler_filter extends views_handler {
* *
* @see options_form() * @see options_form()
*/ */
function expose_form(&$form, &$form_state) { public function expose_form(&$form, &$form_state) {
$form['#theme'] = 'views_ui_expose_filter_form'; $form['#theme'] = 'views_ui_expose_filter_form';
// #flatten will move everything from $form['expose'][$key] to $form[$key] // #flatten will move everything from $form['expose'][$key] to $form[$key]
// prior to rendering. That's why the pre_render for it needs to run first, // prior to rendering. That's why the pre_render for it needs to run first,
@ -566,7 +596,7 @@ class views_handler_filter extends views_handler {
'#description' => t('Remember exposed selection only for the selected user role(s). If you select no roles, the exposed data will never be stored.'), '#description' => t('Remember exposed selection only for the selected user role(s). If you select no roles, the exposed data will never be stored.'),
'#default_value' => $this->options['expose']['remember_roles'], '#default_value' => $this->options['expose']['remember_roles'],
'#options' => $role_options, '#options' => $role_options,
'#dependency' => array( '#dependency' => array(
'edit-options-expose-remember' => array(1), 'edit-options-expose-remember' => array(1),
), ),
); );
@ -584,7 +614,7 @@ class views_handler_filter extends views_handler {
/** /**
* Validate the options form. * Validate the options form.
*/ */
function expose_validate($form, &$form_state) { public function expose_validate($form, &$form_state) {
if (empty($form_state['values']['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.')); form_error($form['expose']['identifier'], t('The identifier is required if the filter is exposed.'));
} }
@ -601,10 +631,10 @@ class views_handler_filter extends views_handler {
} }
} }
/** /**
* Validate the build group options form. * Validate the build group options form.
*/ */
function build_group_validate($form, &$form_state) { public function build_group_validate($form, &$form_state) {
if (!empty($form_state['values']['options']['group_info'])) { if (!empty($form_state['values']['options']['group_info'])) {
if (empty($form_state['values']['options']['group_info']['identifier'])) { if (empty($form_state['values']['options']['group_info']['identifier'])) {
form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.')); form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.'));
@ -625,13 +655,12 @@ class views_handler_filter extends views_handler {
if (!empty($form_state['values']['options']['group_info']['group_items'])) { if (!empty($form_state['values']['options']['group_info']['group_items'])) {
foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) { foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) {
if (empty($group['remove'])) { if (empty($group['remove'])) {
// Check if the title is defined but value wasn't defined. // Check if the title is defined but value wasn't defined.
if (!empty($group['title'])) { if (!empty($group['title'])) {
if ((!is_array($group['value']) && trim($group['value']) == "") || if ((!is_array($group['value']) && trim($group['value']) == "") ||
(is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) == 0)) { (is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) == 0)) {
form_error($form['group_info']['group_items'][$id]['value'], form_error($form['group_info']['group_items'][$id]['value'],
t('The value is required if title for this item is defined.')); t('The value is required if title for this item is defined.'));
} }
} }
@ -640,7 +669,7 @@ class views_handler_filter extends views_handler {
(is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) > 0)) { (is_array($group['value']) && count(array_filter($group['value'], '_views_array_filter_zero')) > 0)) {
if (empty($group['title'])) { if (empty($group['title'])) {
form_error($form['group_info']['group_items'][$id]['title'], form_error($form['group_info']['group_items'][$id]['title'],
t('The title is required if value for this item is defined.')); t('The title is required if value for this item is defined.'));
} }
} }
} }
@ -651,11 +680,11 @@ class views_handler_filter extends views_handler {
/** /**
* Save new group items, re-enumerates and remove groups marked to delete. * Save new group items, re-enumerates and remove groups marked to delete.
*/ */
function build_group_submit($form, &$form_state) { public function build_group_submit($form, &$form_state) {
$groups = array(); $groups = array();
uasort($form_state['values']['options']['group_info']['group_items'], 'drupal_sort_weight'); uasort($form_state['values']['options']['group_info']['group_items'], 'drupal_sort_weight');
// Filter out removed items.
// Filter out removed items.
// Start from 1 to avoid problems with #default_value in the widget. // Start from 1 to avoid problems with #default_value in the widget.
$new_id = 1; $new_id = 1;
$new_default = 'All'; $new_default = 'All';
@ -684,7 +713,7 @@ class views_handler_filter extends views_handler {
/** /**
* Provide default options for exposed filters. * Provide default options for exposed filters.
*/ */
function expose_options() { public function expose_options() {
$this->options['expose'] = array( $this->options['expose'] = array(
'use_operator' => FALSE, 'use_operator' => FALSE,
'operator' => $this->options['id'] . '_op', 'operator' => $this->options['id'] . '_op',
@ -697,10 +726,10 @@ class views_handler_filter extends views_handler {
); );
} }
/** /**
* Provide default options for exposed filters. * Provide default options for exposed filters.
*/ */
function build_group_options() { public function build_group_options() {
$this->options['group_info'] = array( $this->options['group_info'] = array(
'label' => $this->definition['title'], 'label' => $this->definition['title'],
'description' => NULL, 'description' => NULL,
@ -716,12 +745,10 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Build a form containing a group of operator | values to apply as a * Build a form with a group of operator | values to apply as a single filter.
* single filter.
*/ */
function group_form(&$form, &$form_state) { public function group_form(&$form, &$form_state) {
if (!empty($this->options['group_info']['optional']) && !$this->multiple_exposed_input()) { if (!empty($this->options['group_info']['optional']) && !$this->multiple_exposed_input()) {
$old_any = $this->options['group_info']['widget'] == 'select' ? '<Any>' : '&lt;Any&gt;'; $old_any = $this->options['group_info']['widget'] == 'select' ? '<Any>' : '&lt;Any&gt;';
$any_label = variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? $old_any : t('- Any -'); $any_label = variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? $old_any : t('- Any -');
$groups = array('All' => $any_label); $groups = array('All' => $any_label);
@ -750,7 +777,7 @@ class views_handler_filter extends views_handler {
$form[$value]['#multiple'] = TRUE; $form[$value]['#multiple'] = TRUE;
} }
unset($form[$value]['#default_value']); unset($form[$value]['#default_value']);
if (empty($form_state['input'])) { if (empty($form_state['input'][$value])) {
$form_state['input'][$value] = $this->group_info; $form_state['input'][$value] = $this->group_info;
} }
} }
@ -765,7 +792,7 @@ class views_handler_filter extends views_handler {
* *
* You can override this if it doesn't do what you expect. * You can override this if it doesn't do what you expect.
*/ */
function exposed_form(&$form, &$form_state) { public function exposed_form(&$form, &$form_state) {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return; return;
} }
@ -811,18 +838,19 @@ class views_handler_filter extends views_handler {
/** /**
* Build the form to let users create the group of exposed filters. * Build the form to let users create the group of exposed filters.
*
* This form is displayed when users click on button 'Build group' * This form is displayed when users click on button 'Build group'
*/ */
function build_group_form(&$form, &$form_state) { public function build_group_form(&$form, &$form_state) {
if (empty($this->options['exposed']) || empty($this->options['is_grouped'])) { if (empty($this->options['exposed']) || empty($this->options['is_grouped'])) {
return; return;
} }
$form['#theme'] = 'views_ui_build_group_filter_form'; $form['#theme'] = 'views_ui_build_group_filter_form';
// #flatten will move everything from $form['group_info'][$key] to $form[$key] // #flatten will move everything from $form['group_info'][$key] to
// prior to rendering. That's why the pre_render for it needs to run first, // $form[$key] prior to rendering. That's why the pre_render for it needs
// so that when the next pre_render (the one for fieldsets) runs, it gets // to run first, so that when the next pre_render (the one for fieldsets)
// the flattened data. // runs, it gets the flattened data.
array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data'); array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data');
$form['group_info']['#flatten'] = TRUE; $form['group_info']['#flatten'] = TRUE;
@ -925,7 +953,9 @@ class views_handler_filter extends views_handler {
'#default_value' => $this->options['group_info']['remember'], '#default_value' => $this->options['group_info']['remember'],
); );
$groups = array('All' => '- Any -'); // The string '- Any -' will not be rendered see @theme_views_ui_build_group_filter_form // The string '- Any -' will not be rendered.
// @see theme_views_ui_build_group_filter_form()
$groups = array('All' => '- Any -');
// Provide 3 options to start when we are in a new group. // Provide 3 options to start when we are in a new group.
if (count($this->options['group_info']['group_items']) == 0) { if (count($this->options['group_info']['group_items']) == 0) {
@ -939,10 +969,11 @@ class views_handler_filter extends views_handler {
continue; continue;
} }
// Each rows contains three widgets: // Each rows contains three widgets:
// a) The title, where users define how they identify a pair of operator | value // a) The title, where users define how they identify a pair of operator
// b) The operator // | value.
// c) The value (or values) to use in the filter with the selected operator // b) The operator.
// c) The value (or values) to use in the filter with the selected
// operator.
// In each row, we have to display the operator form and the value from // In each row, we have to display the operator form and the value from
// $row acts as a fake form to render each widget in a row. // $row acts as a fake form to render each widget in a row.
$row = array(); $row = array();
@ -954,11 +985,10 @@ class views_handler_filter extends views_handler {
$row['operator']['#title'] = ''; $row['operator']['#title'] = '';
$this->value_form($row, $form_state); $this->value_form($row, $form_state);
// Fix the dependencies to update value forms when operators // Fix the dependencies to update value forms when operators changes.
// changes. This is needed because forms are inside a new form and // This is needed because forms are inside a new form and their ids
// their ids changes. Dependencies are used when operator changes // changes. Dependencies are used when operator changes from to
// from to 'Between', 'Not Between', etc, and two or more widgets // 'Between', 'Not Between', etc, and two or more widgets are displayed.
// are displayed.
$without_children = TRUE; $without_children = TRUE;
foreach (element_children($row['value']) as $children) { foreach (element_children($row['value']) as $children) {
if (isset($row['value'][$children]['#dependency']['edit-options-operator'])) { if (isset($row['value'][$children]['#dependency']['edit-options-operator'])) {
@ -1005,7 +1035,7 @@ class views_handler_filter extends views_handler {
), ),
'weight' => array( 'weight' => array(
'#type' => 'weight', '#type' => 'weight',
'#delta' => 10, '#delta' => count($this->options['group_info']['group_items']),
'#default_value' => $default_weight++, '#default_value' => $default_weight++,
'#attributes' => array('class' => array('weight')), '#attributes' => array('class' => array('weight')),
), ),
@ -1058,10 +1088,9 @@ class views_handler_filter extends views_handler {
/** /**
* Make some translations to a form item to make it more suitable to * Make some translations to a form item to make it more suitable to exposing.
* exposing.
*/ */
function exposed_translate(&$form, $type) { public function exposed_translate(&$form, $type) {
if (!isset($form['#type'])) { if (!isset($form['#type'])) {
return; return;
} }
@ -1083,7 +1112,8 @@ class views_handler_filter extends views_handler {
$form['#size'] = NULL; $form['#size'] = NULL;
} }
// Cleanup in case the translated element's (radios or checkboxes) display value contains html. // Cleanup in case the translated element's (radios or checkboxes) display
// value contains html.
if ($form['#type'] == 'select') { if ($form['#type'] == 'select') {
$this->prepare_filter_select_options($form['#options']); $this->prepare_filter_select_options($form['#options']);
} }
@ -1099,21 +1129,19 @@ class views_handler_filter extends views_handler {
} }
} }
/** /**
* Sanitizes the HTML select element's options. * Sanitizes the HTML select element's options.
* *
* The function is recursive to support optgroups. * The function is recursive to support optgroups.
*/ */
function prepare_filter_select_options(&$options) { public function prepare_filter_select_options(&$options) {
foreach ($options as $value => $label) { foreach ($options as $value => $label) {
// Recurse for optgroups. // Recurse for optgroups.
if (is_array($label)) { if (is_array($label)) {
$this->prepare_filter_select_options($options[$value]); $this->prepare_filter_select_options($options[$value]);
} }
// FAPI has some special value to allow hierarchy. // FAPI has some special value to allow hierarchy.
// @see _form_options_flatten // @see _form_options_flatten()
elseif (is_object($label)) { elseif (is_object($label)) {
$this->prepare_filter_select_options($options[$value]->option); $this->prepare_filter_select_options($options[$value]->option);
} }
@ -1124,8 +1152,10 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Tell the renderer about our exposed form. This only needs to be * Tell the renderer about our exposed form.
* overridden for particularly complex forms. And maybe not even then. *
* This only needs to be overridden for particularly complex forms. And maybe
* not even then.
* *
* @return array|null * @return array|null
* For standard exposed filters. An array with the following keys: * For standard exposed filters. An array with the following keys:
@ -1136,7 +1166,7 @@ class views_handler_filter extends views_handler {
* - value: The $form key of the value. Set to NULL if no value. * - value: The $form key of the value. Set to NULL if no value.
* - label: The label to use for this piece. * - label: The label to use for this piece.
*/ */
function exposed_info() { public function exposed_info() {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return; return;
} }
@ -1157,7 +1187,7 @@ class views_handler_filter extends views_handler {
); );
} }
/* /**
* Transform the input from a grouped filter into a standard filter. * Transform the input from a grouped filter into a standard filter.
* *
* When a filter is a group, find the set of operator and values * When a filter is a group, find the set of operator and values
@ -1168,10 +1198,10 @@ class views_handler_filter extends views_handler {
* checkboxes widget, and this function will be called for each item * checkboxes widget, and this function will be called for each item
* choosed in the checkboxes. * choosed in the checkboxes.
*/ */
function convert_exposed_input(&$input, $selected_group_id = NULL) { public function convert_exposed_input(&$input, $selected_group_id = NULL) {
if ($this->is_a_group()) { if ($this->is_a_group()) {
// If it is already defined the selected group, use it. Only valid // If it is already defined the selected group, use it. Only valid when
// when the filter uses checkboxes for widget. // the filter uses checkboxes for widget.
if (!empty($selected_group_id)) { if (!empty($selected_group_id)) {
$selected_group = $selected_group_id; $selected_group = $selected_group_id;
} }
@ -1187,7 +1217,8 @@ class views_handler_filter extends views_handler {
if (isset($selected_group) && isset($this->options['group_info']['group_items'][$selected_group])) { if (isset($selected_group) && isset($this->options['group_info']['group_items'][$selected_group])) {
$input[$this->options['expose']['operator']] = $this->options['group_info']['group_items'][$selected_group]['operator']; $input[$this->options['expose']['operator']] = $this->options['group_info']['group_items'][$selected_group]['operator'];
// Value can be optional, For example for 'empty' and 'not empty' filters. // Value can be optional, For example for 'empty' and 'not empty'
// filters.
if (!empty($this->options['group_info']['group_items'][$selected_group]['value'])) { if (!empty($this->options['group_info']['group_items'][$selected_group]['value'])) {
$input[$this->options['expose']['identifier']] = $this->options['group_info']['group_items'][$selected_group]['value']; $input[$this->options['expose']['identifier']] = $this->options['group_info']['group_items'][$selected_group]['value'];
} }
@ -1207,7 +1238,7 @@ class views_handler_filter extends views_handler {
* as widget, and therefore has to be applied several times, one per * as widget, and therefore has to be applied several times, one per
* item selected. * item selected.
*/ */
function group_multiple_exposed_input(&$input) { public function group_multiple_exposed_input(&$input) {
if (!empty($input[$this->options['group_info']['identifier']])) { if (!empty($input[$this->options['group_info']['identifier']])) {
return array_filter($input[$this->options['group_info']['identifier']]); return array_filter($input[$this->options['group_info']['identifier']]);
} }
@ -1215,10 +1246,13 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Returns TRUE if users can select multiple groups items of a *
* grouped exposed filter. *
* @return bool
* TRUE if users can select multiple groups items of a grouped exposed
* filter.
*/ */
function multiple_exposed_input() { public function multiple_exposed_input() {
return $this->is_a_group() && !empty($this->options['group_info']['multiple']); return $this->is_a_group() && !empty($this->options['group_info']['multiple']);
} }
@ -1227,7 +1261,7 @@ class views_handler_filter extends views_handler {
* This function is similar to store_exposed_input but modified to * This function is similar to store_exposed_input but modified to
* work properly when the filter is a group. * work properly when the filter is a group.
*/ */
function store_group_input($input, $status) { public function store_group_input($input, $status) {
if (!$this->is_a_group() || empty($this->options['group_info']['identifier'])) { if (!$this->is_a_group() || empty($this->options['group_info']['identifier'])) {
return TRUE; return TRUE;
} }
@ -1236,12 +1270,12 @@ class views_handler_filter extends views_handler {
return; return;
} }
// Figure out which display id is responsible for the filters, so we // Figure out which display id is responsible for the filters, so we know
// know where to look for session stored values. // where to look for session stored values.
$display_id = ($this->view->display_handler->is_defaulted('filters')) ? 'default' : $this->view->current_display; $display_id = ($this->view->display_handler->is_defaulted('filters')) ? 'default' : $this->view->current_display;
// false means that we got a setting that means to recuse ourselves, // False means that we got a setting that means to recuse ourselves, so we
// so we should erase whatever happened to be there. // should erase whatever happened to be there.
if ($status === FALSE && isset($_SESSION['views'][$this->view->name][$display_id])) { if ($status === FALSE && isset($_SESSION['views'][$this->view->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->name][$display_id]; $session = &$_SESSION['views'][$this->view->name][$display_id];
@ -1262,15 +1296,13 @@ class views_handler_filter extends views_handler {
} }
/** /**
* Check to see if input from the exposed filters should change * Check to see if input from the exposed filters should change the behavior.
* the behavior of this filter.
*/ */
function accept_exposed_input($input) { public function accept_exposed_input($input) {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return TRUE; return TRUE;
} }
if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) { if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
$this->operator = $input[$this->options['expose']['operator_id']]; $this->operator = $input[$this->options['expose']['operator_id']];
} }
@ -1295,7 +1327,6 @@ class views_handler_filter extends views_handler {
} }
} }
if (isset($value)) { if (isset($value)) {
$this->value = $value; $this->value = $value;
if (empty($this->always_multiple) && empty($this->options['expose']['multiple'])) { if (empty($this->always_multiple) && empty($this->options['expose']['multiple'])) {
@ -1310,7 +1341,10 @@ class views_handler_filter extends views_handler {
return TRUE; return TRUE;
} }
function store_exposed_input($input, $status) { /**
*
*/
public function store_exposed_input($input, $status) {
if (empty($this->options['exposed']) || empty($this->options['expose']['identifier'])) { if (empty($this->options['exposed']) || empty($this->options['expose']['identifier'])) {
return TRUE; return TRUE;
} }
@ -1327,15 +1361,15 @@ class views_handler_filter extends views_handler {
return; return;
} }
// Figure out which display id is responsible for the filters, so we // Figure out which display id is responsible for the filters, so we know
// know where to look for session stored values. // where to look for session stored values.
$display_id = ($this->view->display_handler->is_defaulted('filters')) ? 'default' : $this->view->current_display; $display_id = ($this->view->display_handler->is_defaulted('filters')) ? 'default' : $this->view->current_display;
// shortcut test. // Shortcut test.
$operator = !empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']); $operator = !empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']);
// false means that we got a setting that means to recuse ourselves, // False means that we got a setting that means to recuse ourselves, so we
// so we should erase whatever happened to be there. // should erase whatever happened to be there.
if (!$status && isset($_SESSION['views'][$this->view->name][$display_id])) { if (!$status && isset($_SESSION['views'][$this->view->name][$display_id])) {
$session = &$_SESSION['views'][$this->view->name][$display_id]; $session = &$_SESSION['views'][$this->view->name][$display_id];
if ($operator && isset($session[$this->options['expose']['operator_id']])) { if ($operator && isset($session[$this->options['expose']['operator_id']])) {
@ -1366,10 +1400,10 @@ class views_handler_filter extends views_handler {
* Add this filter to the query. * Add this filter to the query.
* *
* Due to the nature of fapi, the value and the operator have an unintended * Due to the nature of fapi, the value and the operator have an unintended
* level of indirection. You will find them in $this->operator * level of indirection. You will find them in $this->operator and
* and $this->value respectively. * $this->value respectively.
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", $this->value, $this->operator); $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", $this->value, $this->operator);
} }
@ -1377,16 +1411,18 @@ class views_handler_filter extends views_handler {
/** /**
* Can this filter be used in OR groups? * Can this filter be used in OR groups?
* *
* Some filters have complicated where clauses that cannot be easily used * Some filters have complicated where clauses that cannot be easily used with
* with OR groups. Some filters must also use HAVING which also makes * OR groups. Some filters must also use HAVING which also makes them not
* them not groupable. These filters will end up in a special group * groupable. These filters will end up in a special group if OR grouping is
* if OR grouping is in use. * in use.
* *
* @return bool * @return bool
* Whether the filter can be used in OR groups.
*/ */
function can_group() { public function can_group() {
return TRUE; return TRUE;
} }
} }
@ -1396,27 +1432,51 @@ class views_handler_filter extends views_handler {
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_broken extends views_handler_filter { class views_handler_filter_broken extends views_handler_filter {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query($group_by = FALSE) { /* No query to run */ } * {@inheritdoc}
function options_form(&$form, &$form_state) { */
public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item description">' . 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.') . '</div>', '#markup' => '<div class="form-item description">' . 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.') . '</div>',
); );
} }
/** /**
* Determine if the handler is considered 'broken' * {@inheritdoc}
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }
/** /**
* Filter by no empty values, though allow to use "0". * Filter by no empty values, though allow to use "0".
* @param $var *
* @param string $var
*
* @return bool * @return bool
*/ */
function _views_array_filter_zero($var) { function _views_array_filter_zero($var) {

View File

@ -22,14 +22,26 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_boolean_operator extends views_handler_filter { class views_handler_filter_boolean_operator extends views_handler_filter {
// exposed filter options
var $always_multiple = TRUE;
// Don't display empty space where the operator would be.
var $no_operator = TRUE;
// Whether to accept NULL as a false value or not
var $accept_null = FALSE;
function construct() { /**
* Exposed filter options.
*/
public $always_multiple = TRUE;
/**
* Don't display empty space where the operator would be.
*/
public $no_operator = TRUE;
/**
* Whether to accept NULL as a false value or not.
*/
public $accept_null = FALSE;
/**
* {@inheritdoc}
*/
public function construct() {
$this->value_value = t('True'); $this->value_value = t('True');
if (isset($this->definition['label'])) { if (isset($this->definition['label'])) {
$this->value_value = $this->definition['label']; $this->value_value = $this->definition['label'];
@ -37,7 +49,7 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
if (isset($this->definition['accept null'])) { if (isset($this->definition['accept null'])) {
$this->accept_null = (bool) $this->definition['accept null']; $this->accept_null = (bool) $this->definition['accept null'];
} }
else if (isset($this->definition['accept_null'])) { elseif (isset($this->definition['accept_null'])) {
$this->accept_null = (bool) $this->definition['accept_null']; $this->accept_null = (bool) $this->definition['accept_null'];
} }
$this->value_options = NULL; $this->value_options = NULL;
@ -56,7 +68,7 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
* dynamic for some reason, child classes should use a guard to reduce * dynamic for some reason, child classes should use a guard to reduce
* database hits as much as possible. * database hits as much as possible.
*/ */
function get_value_options() { public function get_value_options() {
if (isset($this->definition['type'])) { if (isset($this->definition['type'])) {
if ($this->definition['type'] == 'yes-no') { if ($this->definition['type'] == 'yes-no') {
$this->value_options = array(1 => t('Yes'), 0 => t('No')); $this->value_options = array(1 => t('Yes'), 0 => t('No'));
@ -75,7 +87,10 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
} }
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['value']['default'] = FALSE; $options['value']['default'] = FALSE;
@ -83,11 +98,17 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
return $options; return $options;
} }
function operator_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function operator_form(&$form, &$form_state) {
$form['operator'] = array(); $form['operator'] = array();
} }
function value_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function value_form(&$form, &$form_state) {
if (empty($this->value_options)) { if (empty($this->value_options)) {
// Initialize the array of possible values for this filter. // Initialize the array of possible values for this filter.
$this->get_value_options(); $this->get_value_options();
@ -122,13 +143,19 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
} }
} }
function value_validate($form, &$form_state) { /**
* {@inheritdoc}
*/
public function value_validate($form, &$form_state) {
if ($form_state['values']['options']['value'] == 'All' && !empty($form_state['values']['options']['expose']['required'])) { if ($form_state['values']['options']['value'] == 'All' && !empty($form_state['values']['options']['expose']['required'])) {
form_set_error('value', t('You must select a value unless this is an non-required exposed filter.')); form_set_error('value', t('You must select a value unless this is an non-required exposed filter.'));
} }
} }
function admin_summary() { /**
* {@inheritdoc}
*/
public function admin_summary() {
if ($this->is_a_group()) { if ($this->is_a_group()) {
return t('grouped'); return t('grouped');
} }
@ -145,14 +172,20 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
return $this->value_options[!empty($this->value)]; return $this->value_options[!empty($this->value)];
} }
function expose_options() { /**
* {@inheritdoc}
*/
public function expose_options() {
parent::expose_options(); parent::expose_options();
$this->options['expose']['operator_id'] = ''; $this->options['expose']['operator_id'] = '';
$this->options['expose']['label'] = $this->value_value; $this->options['expose']['label'] = $this->value_value;
$this->options['expose']['required'] = TRUE; $this->options['expose']['required'] = TRUE;
} }
function query() { /**
* {@inheritdoc}
*/
public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$field = "$this->table_alias.$this->real_field"; $field = "$this->table_alias.$this->real_field";
@ -176,4 +209,5 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
} }
} }
} }
} }

View File

@ -17,7 +17,11 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_boolean_operator_string extends views_handler_filter_boolean_operator { class views_handler_filter_boolean_operator_string extends views_handler_filter_boolean_operator {
function query() {
/**
* {@inheritdoc}
*/
public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$where = "$this->table_alias.$this->real_field "; $where = "$this->table_alias.$this->real_field ";
@ -32,4 +36,5 @@ class views_handler_filter_boolean_operator_string extends views_handler_filter_
} }
$this->query->add_where_expression($this->options['group'], $where); $this->query->add_where_expression($this->options['group'], $where);
} }
} }

View File

@ -11,19 +11,26 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_filter_combine extends views_handler_filter_string { class views_handler_filter_combine extends views_handler_filter_string {
/** /**
* @var views_plugin_query_default * @var views_plugin_query_default
*/ */
public $query; public $query;
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['fields'] = array('default' => array()); $options['fields'] = array('default' => array());
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$this->view->init_style(); $this->view->init_style();
@ -49,7 +56,10 @@ class views_handler_filter_combine extends views_handler_filter_string {
} }
} }
function query() { /**
* {@inheritdoc}
*/
public function query() {
$this->view->_build('field'); $this->view->_build('field');
$fields = array(); $fields = array();
// Only add the fields if they have a proper field and table alias. // Only add the fields if they have a proper field and table alias.
@ -86,20 +96,28 @@ class views_handler_filter_combine extends views_handler_filter_string {
} }
} }
// By default things like op_equal uses add_where, that doesn't support /**
// complex expressions, so override all operators. * By default things like op_equal uses add_where, that doesn't support
function op_equal($field) { * complex expressions, so override all operators.
*/
public function op_equal($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$operator = $this->operator(); $operator = $this->operator();
$this->query->add_where_expression($this->options['group'], "$field $operator $placeholder", array($placeholder => $this->value)); $this->query->add_where_expression($this->options['group'], "$field $operator $placeholder", array($placeholder => $this->value));
} }
function op_contains($field) { /**
*
*/
public function op_contains($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%')); $this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%'));
} }
function op_word($field) { /**
*
*/
public function op_word($field) {
$where = $this->operator == 'word' ? db_or() : db_and(); $where = $this->operator == 'word' ? db_or() : db_and();
// Don't filter on empty strings. // Don't filter on empty strings.
@ -132,37 +150,58 @@ class views_handler_filter_combine extends views_handler_filter_string {
$this->query->add_where($this->options['group'], $where); $this->query->add_where($this->options['group'], $where);
} }
function op_starts($field) { /**
*
*/
public function op_starts($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => db_like($this->value) . '%')); $this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => db_like($this->value) . '%'));
} }
function op_not_starts($field) { /**
*
*/
public function op_not_starts($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => db_like($this->value) . '%')); $this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => db_like($this->value) . '%'));
} }
function op_ends($field) { /**
*
*/
public function op_ends($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value))); $this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value)));
} }
function op_not_ends($field) { /**
*
*/
public function op_not_ends($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value))); $this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value)));
} }
function op_not($field) { /**
*
*/
public function op_not($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%')); $this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%'));
} }
function op_regex($field) { /**
*
*/
public function op_regex($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "$field RLIKE $placeholder", array($placeholder => $this->value)); $this->query->add_where_expression($this->options['group'], "$field RLIKE $placeholder", array($placeholder => $this->value));
} }
function op_empty($field) { /**
*
*/
public function op_empty($field) {
if ($this->operator == 'empty') { if ($this->operator == 'empty') {
$operator = "IS NULL"; $operator = "IS NULL";
} }
@ -172,4 +211,5 @@ class views_handler_filter_combine extends views_handler_filter_string {
$this->query->add_where_expression($this->options['group'], "$field $operator"); $this->query->add_where_expression($this->options['group'], "$field $operator");
} }
} }

View File

@ -11,19 +11,23 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_date extends views_handler_filter_numeric { class views_handler_filter_date extends views_handler_filter_numeric {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
// value is already set up properly, we're just adding our new field to it. // Value is already set up properly, we're just adding our new field to it.
$options['value']['contains']['type']['default'] = 'date'; $options['value']['contains']['type']['default'] = 'date';
return $options; return $options;
} }
/** /**
* Add a type selector to the value form * Add a type selector to the value form.
*/ */
function value_form(&$form, &$form_state) { public function value_form(&$form, &$form_state) {
if (empty($form_state['exposed'])) { if (empty($form_state['exposed'])) {
$form['value']['type'] = array( $form['value']['type'] = array(
'#type' => 'radios', '#type' => 'radios',
@ -38,7 +42,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
parent::value_form($form, $form_state); parent::value_form($form, $form_state);
} }
function options_validate(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_validate(&$form, &$form_state) {
parent::options_validate($form, $form_state); parent::options_validate($form, $form_state);
if (!empty($this->options['exposed']) && empty($form_state['values']['options']['expose']['required'])) { if (!empty($this->options['exposed']) && empty($form_state['values']['options']['expose']['required'])) {
@ -49,7 +56,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
$this->validate_valid_time($form['value'], $form_state['values']['options']['operator'], $form_state['values']['options']['value']); $this->validate_valid_time($form['value'], $form_state['values']['options']['operator'], $form_state['values']['options']['value']);
} }
function exposed_validate(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function exposed_validate(&$form, &$form_state) {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return; return;
} }
@ -74,7 +84,7 @@ class views_handler_filter_date extends views_handler_filter_numeric {
/** /**
* Validate that the time values convert to something usable. * Validate that the time values convert to something usable.
*/ */
function validate_valid_time(&$form, $operator, $value) { public function validate_valid_time(&$form, $operator, $value) {
$operators = $this->operators(); $operators = $this->operators();
if ($operators[$operator]['values'] == 1) { if ($operators[$operator]['values'] == 1) {
@ -98,7 +108,7 @@ class views_handler_filter_date extends views_handler_filter_numeric {
/** /**
* Validate the build group options form. * Validate the build group options form.
*/ */
function build_group_validate($form, &$form_state) { public function build_group_validate($form, &$form_state) {
// Special case to validate grouped date filters, this is because the // Special case to validate grouped date filters, this is because the
// $group['value'] array contains the type of filter (date or offset) // $group['value'] array contains the type of filter (date or offset)
// and therefore the number of items the comparission has to be done // and therefore the number of items the comparission has to be done
@ -122,8 +132,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
} }
} }
/**
function accept_exposed_input($input) { * {@inheritdoc}
*/
public function accept_exposed_input($input) {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return TRUE; return TRUE;
} }
@ -152,30 +164,39 @@ class views_handler_filter_date extends views_handler_filter_numeric {
} }
} }
// restore what got overwritten by the parent. // Restore what got overwritten by the parent.
$this->value['type'] = $type; $this->value['type'] = $type;
return $rc; return $rc;
} }
function op_between($field) { /**
*
*/
public function op_between($field) {
// Use the substitutions to ensure a consistent timestamp. // Use the substitutions to ensure a consistent timestamp.
$query_substitutions = views_views_query_substitutions($this->view); $query_substitutions = views_views_query_substitutions($this->view);
$a = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***'])); $a = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***']));
$b = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***'])); $b = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***']));
// This is safe because we are manually scrubbing the values. // This is safe because we are manually scrubbing the values. It is
// It is necessary to do it this way because $a and $b are formulas when using an offset. // necessary to do it this way because $a and $b are formulas when using an
// offset.
$operator = strtoupper($this->operator); $operator = strtoupper($this->operator);
$this->query->add_where_expression($this->options['group'], "$field $operator $a AND $b"); $this->query->add_where_expression($this->options['group'], "$field $operator $a AND $b");
} }
function op_simple($field) { /**
*
*/
public function op_simple($field) {
// Use the substitutions to ensure a consistent timestamp. // Use the substitutions to ensure a consistent timestamp.
$query_substitutions = views_views_query_substitutions($this->view); $query_substitutions = views_views_query_substitutions($this->view);
$value = intval(strtotime($this->value['value'], $query_substitutions['***CURRENT_TIME***'])); $value = intval(strtotime($this->value['value'], $query_substitutions['***CURRENT_TIME***']));
// This is safe because we are manually scrubbing the value. // This is safe because we are manually scrubbing the value. It is
// It is necessary to do it this way because $value is a formula when using an offset. // necessary to do it this way because $value is a formula when using an
// offset.
$this->query->add_where_expression($this->options['group'], "$field $this->operator $value"); $this->query->add_where_expression($this->options['group'], "$field $this->operator $value");
} }
} }

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Definition of views_handler_filter_entity_bundle * Definition of views_handler_filter_entity_bundle.
*/ */
/** /**
@ -13,6 +13,7 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_entity_bundle extends views_handler_filter_in_operator { class views_handler_filter_entity_bundle extends views_handler_filter_in_operator {
/** /**
* Stores the entity type on which the filter filters. * Stores the entity type on which the filter filters.
* *
@ -20,7 +21,10 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
*/ */
public $entity_type; public $entity_type;
function init(&$view, &$options) { /**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
$this->get_entity_type(); $this->get_entity_type();
@ -32,16 +36,17 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
* @return string * @return string
* The entity type on the filter. * The entity type on the filter.
*/ */
function get_entity_type() { public function get_entity_type() {
if (!isset($this->entity_type)) { if (!isset($this->entity_type)) {
$data = views_fetch_data($this->table); $data = views_fetch_data($this->table);
if (isset($data['table']['entity type'])) { if (isset($data['table']['entity type'])) {
$this->entity_type = $data['table']['entity type']; $this->entity_type = $data['table']['entity type'];
} }
// If the current filter is under a relationship you can't be sure that the // If the current filter is under a relationship you can't be sure that
// entity type of the view is the entity type of the current filter // the entity type of the view is the entity type of the current filter
// For example a filter from a node author on a node view does have users as entity type. // For example a filter from a node author on a node view does have users
// as entity type.
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') { if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
$relationships = $this->view->display_handler->get_option('relationships'); $relationships = $this->view->display_handler->get_option('relationships');
if (!empty($relationships[$this->options['relationship']])) { if (!empty($relationships[$this->options['relationship']])) {
@ -55,8 +60,10 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
return $this->entity_type; return $this->entity_type;
} }
/**
function get_value_options() { * {@inheritdoc}
*/
public function get_value_options() {
if (!isset($this->value_options)) { if (!isset($this->value_options)) {
$info = entity_get_info($this->entity_type); $info = entity_get_info($this->entity_type);
$types = $info['bundles']; $types = $info['bundles'];
@ -76,7 +83,7 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
* bundle, though these two need an additional join to node/vocab table * bundle, though these two need an additional join to node/vocab table
* to work as required. * to work as required.
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
// Adjust the join for the comment case. // Adjust the join for the comment case.
@ -119,4 +126,5 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
} }
parent::query(); parent::query();
} }
} }

View File

@ -6,18 +6,21 @@
*/ */
/** /**
* Simple filter to handle equal to / not equal to filters * Simple filter to handle equal to / not equal to filters.
* *
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_equality extends views_handler_filter { class views_handler_filter_equality extends views_handler_filter {
// exposed filter options
var $always_multiple = TRUE;
/** /**
* Provide simple equality operator * Exposed filter options.
*/ */
function operator_options() { public $always_multiple = TRUE;
/**
* Provide simple equality operator.
*/
public function operator_options() {
return array( return array(
'=' => t('Is equal to'), '=' => t('Is equal to'),
'!=' => t('Is not equal to'), '!=' => t('Is not equal to'),
@ -25,9 +28,9 @@ class views_handler_filter_equality extends views_handler_filter {
} }
/** /**
* Provide a simple textfield for equality * Provide a simple textfield for equality.
*/ */
function value_form(&$form, &$form_state) { public function value_form(&$form, &$form_state) {
$form['value'] = array( $form['value'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Value'), '#title' => t('Value'),
@ -42,4 +45,5 @@ class views_handler_filter_equality extends views_handler_filter {
} }
} }
} }
} }

View File

@ -10,17 +10,19 @@
* *
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_fields_compare extends views_handler_filter { class views_handler_filter_fields_compare extends views_handler_filter {
function can_expose() { /**
* {@inheritdoc}
*/
public function can_expose() {
return FALSE; return FALSE;
} }
/** /**
* Overrides views_handler_filter#option_definition(). * {@inheritdoc}
*/ */
function option_definition() { public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['left_field'] = $options['right_field'] = array('default' => ''); $options['left_field'] = $options['right_field'] = array('default' => '');
@ -31,21 +33,21 @@ class views_handler_filter_fields_compare extends views_handler_filter {
/** /**
* Provide a list of all operators. * Provide a list of all operators.
*/ */
function fields_operator_options() { public function fields_operator_options() {
return array( return array(
'<' => t('Is less than'), '<' => t('Is less than'),
'<=' => t('Is less than or equal to'), '<=' => t('Is less than or equal to'),
'=' => t('Is equal to'), '=' => t('Is equal to'),
'<>' => t('Is not equal to'), '<>' => t('Is not equal to'),
'>=' => t('Is greater than or equal to'), '>=' => t('Is greater than or equal to'),
'>' => t('Is greater than') '>' => t('Is greater than'),
); );
} }
/** /**
* Provide a list of available fields. * Provide a list of available fields.
*/ */
function field_options() { public function field_options() {
$options = array(); $options = array();
$field_handlers = $this->view->display_handler->get_handlers('field'); $field_handlers = $this->view->display_handler->get_handlers('field');
@ -59,9 +61,9 @@ class views_handler_filter_fields_compare extends views_handler_filter {
} }
/** /**
* Overrides views_handler_filter#options_form(). * {@inheritdoc}
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$field_options = $this->field_options(); $field_options = $this->field_options();
@ -93,11 +95,10 @@ class views_handler_filter_fields_compare extends views_handler_filter {
} }
/** /**
* Overrides views_handler_filter#query(). * {@inheritdoc}
*
* Build extra condition from existing fields (from existing joins).
*/ */
function query() { public function query() {
// Build extra condition from existing fields (from existing joins).
$left = $this->options['left_field']; $left = $this->options['left_field'];
$right = $this->options['right_field']; $right = $this->options['right_field'];
@ -120,22 +121,21 @@ class views_handler_filter_fields_compare extends views_handler_filter {
$right_table_alias = $this->query->ensure_table($right_handler->table, $right_handler->relationship); $right_table_alias = $this->query->ensure_table($right_handler->table, $right_handler->relationship);
// Build piece of SQL. // Build piece of SQL.
$snippet = $snippet = $left_table_alias . '.' . $left_handler->real_field
$left_table_alias . '.' . $left_handler->real_field . . ' ' . $this->options['operator'] . ' '
' ' . $this->options['operator'] . ' ' . . $right_table_alias . '.' . $right_handler->real_field;
$right_table_alias . '.' . $right_handler->real_field;
$this->query->add_where_expression($this->options['group'], $snippet); $this->query->add_where_expression($this->options['group'], $snippet);
} }
/** /**
* Overrides views_handler_filter#admin_summary(). * {@inheritdoc}
*/ */
function admin_summary() { public function admin_summary() {
return check_plain( return check_plain(
$this->options['left_field'] . ' ' . $this->options['left_field'] . ' '
$this->options['operator'] . ' ' . . $this->options['operator'] . ' '
$this->options['right_field'] . $this->options['right_field']
); );
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_group_by_numeric extends views_handler_filter_numeric { class views_handler_filter_group_by_numeric extends views_handler_filter_numeric {
function query() {
/**
* {@inheritdoc}
*/
public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$field = $this->get_field(); $field = $this->get_field();
@ -20,7 +24,11 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
$this->{$info[$this->operator]['method']}($field); $this->{$info[$this->operator]['method']}($field);
} }
} }
function op_between($field) {
/**
* {@inheritdoc}
*/
public function op_between($field) {
$placeholder_min = $this->placeholder(); $placeholder_min = $this->placeholder();
$placeholder_max = $this->placeholder(); $placeholder_max = $this->placeholder();
if ($this->operator == 'between') { if ($this->operator == 'between') {
@ -32,12 +40,18 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
} }
} }
function op_simple($field) { /**
* {@inheritdoc}
*/
public function op_simple($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_having_expression($this->options['group'], "$field $this->operator $placeholder", array($placeholder => $this->value['value'])); $this->query->add_having_expression($this->options['group'], "$field $this->operator $placeholder", array($placeholder => $this->value['value']));
} }
function op_empty($field) { /**
* {@inheritdoc}
*/
public function op_empty($field) {
if ($this->operator == 'empty') { if ($this->operator == 'empty') {
$operator = "IS NULL"; $operator = "IS NULL";
} }
@ -48,9 +62,18 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
$this->query->add_having_expression($this->options['group'], "$field $operator"); $this->query->add_having_expression($this->options['group'], "$field $operator");
} }
function ui_name($short = FALSE) { /**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return $this->get_field(parent::ui_name($short)); return $this->get_field(parent::ui_name($short));
} }
function can_group() { return FALSE; } /**
* {@inheritdoc}
*/
public function can_group() {
return FALSE;
}
} }

View File

@ -6,24 +6,32 @@
*/ */
/** /**
* Simple filter to handle matching of multiple options selectable via checkboxes * Simple filter to handle matching of multiple options using checkboxes.
* *
* Definition items: * Definition items:
* - options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used. * - options callback: The function to call in order to generate the value
* options. If omitted, the options 'Yes' and 'No' will be used.
* - options arguments: An array of arguments to pass to the options callback. * - options arguments: An array of arguments to pass to the options callback.
* *
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_in_operator extends views_handler_filter { class views_handler_filter_in_operator extends views_handler_filter {
var $value_form_type = 'checkboxes';
/**
*
*/
public $value_form_type = 'checkboxes';
/** /**
* @var array * @var array
* Stores all operations which are available on the form. * Stores all operations which are available on the form.
*/ */
var $value_options = NULL; public $value_options = NULL;
function construct() { /**
* {@inheritdoc}
*/
public function construct() {
parent::construct(); parent::construct();
$this->value_title = t('Options'); $this->value_title = t('Options');
$this->value_options = NULL; $this->value_options = NULL;
@ -40,7 +48,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
* @return * @return
* Return the stored values in $this->value_options if someone expects it. * Return the stored values in $this->value_options if someone expects it.
*/ */
function get_value_options() { public function get_value_options() {
if (isset($this->value_options)) { if (isset($this->value_options)) {
return; return;
} }
@ -60,22 +68,32 @@ class views_handler_filter_in_operator extends views_handler_filter {
return $this->value_options; return $this->value_options;
} }
function expose_options() { /**
* {@inheritdoc}
*/
public function expose_options() {
parent::expose_options(); parent::expose_options();
$this->options['expose']['reduce'] = FALSE; $this->options['expose']['reduce'] = FALSE;
} }
function expose_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function expose_form(&$form, &$form_state) {
parent::expose_form($form, $form_state); parent::expose_form($form, $form_state);
$form['expose']['reduce'] = array( $form['expose']['reduce'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Limit list to selected items'), '#title' => t('Limit list to selected items'),
'#description' => t('If checked, the only items presented to the user will be the ones selected here.'), '#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 // Safety.
'#default_value' => !empty($this->options['expose']['reduce']),
); );
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['operator']['default'] = 'in'; $options['operator']['default'] = 'in';
@ -86,11 +104,11 @@ class views_handler_filter_in_operator extends views_handler_filter {
} }
/** /**
* This kind of construct makes it relatively easy for a child class * This kind of construct makes it relatively easy for a child class to add or
* to add or remove functionality by overriding this function and * remove functionality by overriding this function and adding/removing items
* adding/removing items from this array. * from this array.
*/ */
function operators() { public function operators() {
$operators = array( $operators = array(
'in' => array( 'in' => array(
'title' => t('Is one of'), 'title' => t('Is one of'),
@ -129,9 +147,9 @@ class views_handler_filter_in_operator extends views_handler_filter {
} }
/** /**
* Build strings from the operators() for 'select' options * Build strings from the operators() for 'select' options.
*/ */
function operator_options($which = 'title') { public function operator_options($which = 'title') {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
$options[$id] = $info[$which]; $options[$id] = $info[$which];
@ -140,7 +158,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
return $options; return $options;
} }
function operator_values($values = 1) { /**
* {@inheritdoc}
*/
public function operator_values($values = 1) {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
if (isset($info['values']) && $info['values'] == $values) { if (isset($info['values']) && $info['values'] == $values) {
@ -151,7 +172,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
return $options; return $options;
} }
function value_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function value_form(&$form, &$form_state) {
$form['value'] = array(); $form['value'] = array();
$options = array(); $options = array();
@ -172,7 +196,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
$identifier = $this->options['expose']['identifier']; $identifier = $this->options['expose']['identifier'];
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) { if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
// exposed and locked. // Exposed and locked.
$which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none'; $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
} }
else { else {
@ -229,7 +253,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
/** /**
* When using exposed filters, we may be required to reduce the set. * When using exposed filters, we may be required to reduce the set.
*/ */
function reduce_value_options($input = NULL) { public function reduce_value_options($input = NULL) {
if (!isset($input)) { if (!isset($input)) {
$input = $this->value_options; $input = $this->value_options;
} }
@ -257,9 +281,12 @@ class views_handler_filter_in_operator extends views_handler_filter {
return $options; return $options;
} }
function accept_exposed_input($input) { /**
* {@inheritdoc}
*/
public function accept_exposed_input($input) {
// A very special override because the All state for this type of // A very special override because the All state for this type of
// filter could have a default: // filter could have a default.
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return TRUE; return TRUE;
} }
@ -276,7 +303,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
return parent::accept_exposed_input($input); return parent::accept_exposed_input($input);
} }
function value_submit($form, &$form_state) { /**
* {@inheritdoc}
*/
public function value_submit($form, &$form_state) {
// Drupal's FAPI system automatically puts '0' in for any checkbox that // 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. // 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, // Unfortunately, this means that if the key to that checkbox is 0,
@ -289,7 +319,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
$form_state['values']['options']['value'] = $form['value']['#value']; $form_state['values']['options']['value'] = $form['value']['#value'];
} }
function admin_summary() { /**
* {@inheritdoc}
*/
public function admin_summary() {
if ($this->is_a_group()) { if ($this->is_a_group()) {
return t('grouped'); return t('grouped');
} }
@ -317,7 +350,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
if (count($this->value) == 0) { if (count($this->value) == 0) {
$values = t('Unknown'); $values = t('Unknown');
} }
else if (count($this->value) == 1) { elseif (count($this->value) == 1) {
// If any, use the 'single' short name of the operator instead. // If any, use the 'single' short name of the operator instead.
if (isset($info[$this->operator]['short_single'])) { if (isset($info[$this->operator]['short_single'])) {
$operator = check_plain($info[$this->operator]['short_single']); $operator = check_plain($info[$this->operator]['short_single']);
@ -351,14 +384,20 @@ class views_handler_filter_in_operator extends views_handler_filter {
return $operator . (($values !== '') ? ' ' . $values : ''); return $operator . (($values !== '') ? ' ' . $values : '');
} }
function query() { /**
* {@inheritdoc}
*/
public function query() {
$info = $this->operators(); $info = $this->operators();
if (!empty($info[$this->operator]['method'])) { if (!empty($info[$this->operator]['method'])) {
$this->{$info[$this->operator]['method']}(); $this->{$info[$this->operator]['method']}();
} }
} }
function op_simple() { /**
* {@inheritdoc}
*/
public function op_simple() {
if (empty($this->value)) { if (empty($this->value)) {
return; return;
} }
@ -369,7 +408,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", array_values($this->value), $this->operator); $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", array_values($this->value), $this->operator);
} }
function op_empty() { /**
* {@inheritdoc}
*/
public function op_empty() {
$this->ensure_my_table(); $this->ensure_my_table();
if ($this->operator == 'empty') { if ($this->operator == 'empty') {
$operator = "IS NULL"; $operator = "IS NULL";
@ -381,7 +423,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", NULL, $operator); $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", NULL, $operator);
} }
function validate() { /**
* {@inheritdoc}
*/
public function validate() {
$this->get_value_options(); $this->get_value_options();
$errors = array(); $errors = array();
@ -396,11 +441,13 @@ class views_handler_filter_in_operator extends views_handler_filter {
} }
if (is_array($this->value)) { if (is_array($this->value)) {
if (!isset($this->value_options)) { if (!isset($this->value_options)) {
// Don't validate if there are none value options provided, for example for special handlers. // Don't validate if there are none value options provided, for example
// for special handlers.
return $errors; return $errors;
} }
if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) { if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) {
// Don't validate if the field is exposed and no default value is provided. // Don't validate if the field is exposed and no default value is
// provided.
return $errors; return $errors;
} }
@ -423,4 +470,5 @@ class views_handler_filter_in_operator extends views_handler_filter {
} }
return $errors; return $errors;
} }
} }

View File

@ -6,8 +6,9 @@
*/ */
/** /**
* Complex filter to handle filtering for many to one relationships, * Complex filter to handle filtering for many to one relationships.
* such as terms (many terms per node) or roles (many roles per user). *
* Examples: terms (many terms per node), roles (many roles per user).
* *
* The construct method needs to be overridden to provide a list of options; * The construct method needs to be overridden to provide a list of options;
* alternately, the value_form and admin_summary methods need to be overriden * alternately, the value_form and admin_summary methods need to be overriden
@ -16,19 +17,31 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_many_to_one extends views_handler_filter_in_operator { class views_handler_filter_many_to_one extends views_handler_filter_in_operator {
/** /**
* @var views_many_to_one_helper * @var views_many_to_one_helper
* *
* Stores the Helper object which handles the many_to_one complexity. * Stores the Helper object which handles the many_to_one complexity.
*/ */
var $helper = NULL; public $helper = NULL;
function init(&$view, &$options) { /**
*
*/
public $value_form_type = 'select';
/**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
$this->helper = new views_many_to_one_helper($this); $this->helper = new views_many_to_one_helper($this);
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['operator']['default'] = 'or'; $options['operator']['default'] = 'or';
@ -45,7 +58,10 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
return $options; return $options;
} }
function operators() { /**
* {@inheritdoc}
*/
public function operators() {
$operators = array( $operators = array(
'or' => array( 'or' => array(
'title' => t('Is one of'), 'title' => t('Is one of'),
@ -93,8 +109,10 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
return $operators; return $operators;
} }
var $value_form_type = 'select'; /**
function value_form(&$form, &$form_state) { * {@inheritdoc}
*/
public function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state); parent::value_form($form, $form_state);
if (empty($form_state['exposed'])) { if (empty($form_state['exposed'])) {
@ -106,7 +124,7 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
* Override ensure_my_table so we can control how this joins in. * Override ensure_my_table so we can control how this joins in.
* The operator actually has influence over joining. * The operator actually has influence over joining.
*/ */
function ensure_my_table() { public function ensure_my_table() {
// Defer to helper if the operator specifies it. // Defer to helper if the operator specifies it.
$info = $this->operators(); $info = $this->operators();
if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') { if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') {
@ -116,10 +134,14 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
return parent::ensure_my_table(); return parent::ensure_my_table();
} }
function op_helper() { /**
* {@inheritdoc}
*/
public function op_helper() {
if (empty($this->value)) { if (empty($this->value)) {
return; return;
} }
$this->helper->add_filter(); $this->helper->add_filter();
} }
} }

View File

@ -11,8 +11,16 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_numeric extends views_handler_filter { class views_handler_filter_numeric extends views_handler_filter {
var $always_multiple = TRUE;
function option_definition() { /**
* Exposed filter options.
*/
public $always_multiple = TRUE;
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['value'] = array( $options['value'] = array(
@ -26,7 +34,10 @@ class views_handler_filter_numeric extends views_handler_filter {
return $options; return $options;
} }
function operators() { /**
* {@inheritdoc}
*/
public function operators() {
$operators = array( $operators = array(
'<' => array( '<' => array(
'title' => t('Is less than'), 'title' => t('Is less than'),
@ -114,7 +125,7 @@ class views_handler_filter_numeric extends views_handler_filter {
/** /**
* Provide a list of all the numeric operators * Provide a list of all the numeric operators
*/ */
function operator_options($which = 'title') { public function operator_options($which = 'title') {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
$options[$id] = $info[$which]; $options[$id] = $info[$which];
@ -123,7 +134,10 @@ class views_handler_filter_numeric extends views_handler_filter {
return $options; return $options;
} }
function operator_values($values = 1) { /**
* {@inheritdoc}
*/
public function operator_values($values = 1) {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
if ($info['values'] == $values) { if ($info['values'] == $values) {
@ -133,10 +147,11 @@ class views_handler_filter_numeric extends views_handler_filter {
return $options; return $options;
} }
/** /**
* Provide a simple textfield for equality * Provide a simple textfield for equality
*/ */
function value_form(&$form, &$form_state) { public function value_form(&$form, &$form_state) {
$form['value']['#tree'] = TRUE; $form['value']['#tree'] = TRUE;
// We have to make some choices when creating this as an exposed // We have to make some choices when creating this as an exposed
@ -223,7 +238,10 @@ class views_handler_filter_numeric extends views_handler_filter {
} }
} }
function query() { /**
* {@inheritdoc}
*/
public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$field = "$this->table_alias.$this->real_field"; $field = "$this->table_alias.$this->real_field";
@ -233,7 +251,10 @@ class views_handler_filter_numeric extends views_handler_filter {
} }
} }
function op_between($field) { /**
* {@inheritdoc}
*/
public function op_between($field) {
if ($this->operator == 'between') { if ($this->operator == 'between') {
$this->query->add_where($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'BETWEEN'); $this->query->add_where($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'BETWEEN');
} }
@ -242,11 +263,17 @@ class views_handler_filter_numeric extends views_handler_filter {
} }
} }
function op_simple($field) { /**
* {@inheritdoc}
*/
public function op_simple($field) {
$this->query->add_where($this->options['group'], $field, $this->value['value'], $this->operator); $this->query->add_where($this->options['group'], $field, $this->value['value'], $this->operator);
} }
function op_empty($field) { /**
* {@inheritdoc}
*/
public function op_empty($field) {
if ($this->operator == 'empty') { if ($this->operator == 'empty') {
$operator = "IS NULL"; $operator = "IS NULL";
} }
@ -257,11 +284,17 @@ class views_handler_filter_numeric extends views_handler_filter {
$this->query->add_where($this->options['group'], $field, NULL, $operator); $this->query->add_where($this->options['group'], $field, NULL, $operator);
} }
function op_regex($field) { /**
* {@inheritdoc}
*/
public function op_regex($field) {
$this->query->add_where($this->options['group'], $field, $this->value['value'], 'RLIKE'); $this->query->add_where($this->options['group'], $field, $this->value['value'], 'RLIKE');
} }
function admin_summary() { /**
* {@inheritdoc}
*/
public function admin_summary() {
if ($this->is_a_group()) { if ($this->is_a_group()) {
return t('grouped'); return t('grouped');
} }
@ -281,15 +314,15 @@ class views_handler_filter_numeric extends views_handler_filter {
} }
/** /**
* Do some minor translation of the exposed input * Do some minor translation of the exposed input.
*/ */
function accept_exposed_input($input) { public function accept_exposed_input($input) {
if (empty($this->options['exposed'])) { if (empty($this->options['exposed'])) {
return TRUE; return TRUE;
} }
// rewrite the input value so that it's in the correct format so that // Rewrite the input value so that it's in the correct format so that the
// the parent gets the right data. // parent gets the right data.
if (!empty($this->options['expose']['identifier'])) { if (!empty($this->options['expose']['identifier'])) {
$value = &$input[$this->options['expose']['identifier']]; $value = &$input[$this->options['expose']['identifier']];
if (!is_array($value)) { if (!is_array($value)) {
@ -311,6 +344,7 @@ class views_handler_filter_numeric extends views_handler_filter {
return FALSE; return FALSE;
} }
break; break;
case 2: case 2:
if ($value['min'] === '' && $value['max'] === '') { if ($value['min'] === '' && $value['max'] === '') {
return FALSE; return FALSE;
@ -322,4 +356,5 @@ class views_handler_filter_numeric extends views_handler_filter {
return $rc; return $rc;
} }
} }

View File

@ -12,10 +12,16 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_string extends views_handler_filter { class views_handler_filter_string extends views_handler_filter {
// exposed filter options
var $always_multiple = TRUE;
function option_definition() { /**
* Exposed filter options.
*/
public $always_multiple = TRUE;
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE); $options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE);
@ -24,11 +30,11 @@ class views_handler_filter_string extends views_handler_filter {
} }
/** /**
* This kind of construct makes it relatively easy for a child class * This kind of construct makes it relatively easy for a child class to add or
* to add or remove functionality by overriding this function and * remove functionality by overriding this function and adding/removing items
* adding/removing items from this array. * from this array.
*/ */
function operators() { public function operators() {
$operators = array( $operators = array(
'=' => array( '=' => array(
'title' => t('Is equal to'), 'title' => t('Is equal to'),
@ -103,7 +109,7 @@ class views_handler_filter_string extends views_handler_filter {
'values' => 1, 'values' => 1,
), ),
); );
// if the definition allows for the empty operator, add it. // If the definition allows for the empty operator, add it.
if (!empty($this->definition['allow empty'])) { if (!empty($this->definition['allow empty'])) {
$operators += array( $operators += array(
'empty' => array( 'empty' => array(
@ -136,9 +142,9 @@ class views_handler_filter_string extends views_handler_filter {
} }
/** /**
* Build strings from the operators() for 'select' options * Build strings from the operators() for 'select' options.
*/ */
function operator_options($which = 'title') { public function operator_options($which = 'title') {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
$options[$id] = $info[$which]; $options[$id] = $info[$which];
@ -147,7 +153,10 @@ class views_handler_filter_string extends views_handler_filter {
return $options; return $options;
} }
function admin_summary() { /**
* {@inheritdoc}
*/
public function admin_summary() {
if ($this->is_a_group()) { if ($this->is_a_group()) {
return t('grouped'); return t('grouped');
} }
@ -157,7 +166,7 @@ class views_handler_filter_string extends views_handler_filter {
$options = $this->operator_options('short'); $options = $this->operator_options('short');
$output = ''; $output = '';
if(!empty($options[$this->operator])) { if (!empty($options[$this->operator])) {
$output = check_plain($options[$this->operator]); $output = check_plain($options[$this->operator]);
} }
if (in_array($this->operator, $this->operator_values(1))) { if (in_array($this->operator, $this->operator_values(1))) {
@ -166,7 +175,10 @@ class views_handler_filter_string extends views_handler_filter {
return $output; return $output;
} }
function operator_values($values = 1) { /**
* {@inheritdoc}
*/
public function operator_values($values = 1) {
$options = array(); $options = array();
foreach ($this->operators() as $id => $info) { foreach ($this->operators() as $id => $info) {
if (isset($info['values']) && $info['values'] == $values) { if (isset($info['values']) && $info['values'] == $values) {
@ -178,13 +190,12 @@ class views_handler_filter_string extends views_handler_filter {
} }
/** /**
* Provide a simple textfield for equality * Provide a simple textfield for equality.
*/ */
function value_form(&$form, &$form_state) { public function value_form(&$form, &$form_state) {
// We have to make some choices when creating this as an exposed // We have to make some choices when creating this as an exposed filter
// filter form. For example, if the operator is locked and thus // form. For example, if the operator is locked and thus not rendered, we
// not rendered, we can't render dependencies; instead we only // can't render dependencies; instead we only render the form items we need.
// render the form items we need.
$which = 'all'; $which = 'all';
if (!empty($form['operator'])) { if (!empty($form['operator'])) {
$source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator'; $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
@ -223,23 +234,26 @@ class views_handler_filter_string extends views_handler_filter {
// Ensure there is something in the 'value'. // Ensure there is something in the 'value'.
$form['value'] = array( $form['value'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => NULL '#value' => NULL,
); );
} }
} }
function operator() { /**
* {@inheritdoc}
*/
public function operator() {
return $this->operator == '=' ? 'LIKE' : 'NOT LIKE'; return $this->operator == '=' ? 'LIKE' : 'NOT LIKE';
} }
/** /**
* Add this filter to the query. * Add this filter to the query.
* *
* Due to the nature of fapi, the value and the operator have an unintended * Due to the nature of FAPI, the value and the operator have an unintended
* level of indirection. You will find them in $this->operator * level of indirection. You will find them in $this->operator and
* and $this->value respectively. * $this->value respectively.
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$field = "$this->table_alias.$this->real_field"; $field = "$this->table_alias.$this->real_field";
@ -249,15 +263,24 @@ class views_handler_filter_string extends views_handler_filter {
} }
} }
function op_equal($field) { /**
* {@inheritdoc}
*/
public function op_equal($field) {
$this->query->add_where($this->options['group'], $field, $this->value, $this->operator()); $this->query->add_where($this->options['group'], $field, $this->value, $this->operator());
} }
function op_contains($field) { /**
* {@inheritdoc}
*/
public function op_contains($field) {
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE'); $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE');
} }
function op_word($field) { /**
* {@inheritdoc}
*/
public function op_word($field) {
$where = $this->operator == 'word' ? db_or() : db_and(); $where = $this->operator == 'word' ? db_or() : db_and();
// Don't filter on empty strings. // Don't filter on empty strings.
@ -267,11 +290,11 @@ class views_handler_filter_string extends views_handler_filter {
preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER); preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
foreach ($matches as $match) { foreach ($matches as $match) {
$phrase = false; $phrase = FALSE;
// Strip off phrase quotes // Strip off phrase quotes
if ($match[2]{0} == '"') { if ($match[2]{0} == '"') {
$match[2] = substr($match[2], 1, -1); $match[2] = substr($match[2], 1, -1);
$phrase = true; $phrase = TRUE;
} }
$words = trim($match[2], ',?!();:-'); $words = trim($match[2], ',?!();:-');
$words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY); $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
@ -285,46 +308,73 @@ class views_handler_filter_string extends views_handler_filter {
return; return;
} }
// previously this was a call_user_func_array but that's unnecessary // Previously this was a call_user_func_array but that's unnecessary as
// as views will unpack an array that is a single arg. // Views will unpack an array that is a single arg.
$this->query->add_where($this->options['group'], $where); $this->query->add_where($this->options['group'], $where);
} }
function op_starts($field) { /**
* {@inheritdoc}
*/
public function op_starts($field) {
$this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE'); $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE');
} }
function op_not_starts($field) { /**
* {@inheritdoc}
*/
public function op_not_starts($field) {
$this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE'); $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE');
} }
function op_ends($field) { /**
* {@inheritdoc}
*/
public function op_ends($field) {
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'LIKE'); $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'LIKE');
} }
function op_not_ends($field) { /**
* {@inheritdoc}
*/
public function op_not_ends($field) {
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'NOT LIKE'); $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'NOT LIKE');
} }
function op_not($field) { /**
* {@inheritdoc}
*/
public function op_not($field) {
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'NOT LIKE'); $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'NOT LIKE');
} }
function op_shorter($field) { /**
* {@inheritdoc}
*/
public function op_shorter($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => $this->value)); $this->query->add_where_expression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => $this->value));
} }
function op_longer($field) { /**
* {@inheritdoc}
*/
public function op_longer($field) {
$placeholder = $this->placeholder(); $placeholder = $this->placeholder();
$this->query->add_where_expression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => $this->value)); $this->query->add_where_expression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => $this->value));
} }
function op_regex($field) { /**
* {@inheritdoc}
*/
public function op_regex($field) {
$this->query->add_where($this->options['group'], $field, $this->value, 'RLIKE'); $this->query->add_where($this->options['group'], $field, $this->value, 'RLIKE');
} }
function op_empty($field) { /**
* {@inheritdoc}
*/
public function op_empty($field) {
if ($this->operator == 'empty') { if ($this->operator == 'empty') {
$operator = "IS NULL"; $operator = "IS NULL";
} }

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Views' relationship handlers. * Definition of views_handler_relationship.
*/ */
/** /**
@ -12,12 +12,11 @@
*/ */
/** /**
* Simple relationship handler that allows a new version of the primary table * Relationship handler, allows a new version of the primary table to be linked.
* to be linked in.
* *
* The base relationship handler can only handle a single join. Some relationships * The base relationship handler can only handle a single join. Some
* are more complex and might require chains of joins; for those, you must * relationships are more complex and might require chains of joins; for those,
* utilize a custom relationship handler. * you must use a custom relationship handler.
* *
* Definition items: * Definition items:
* - base: The new base table this relationship will be adding. This does not * - base: The new base table this relationship will be adding. This does not
@ -36,18 +35,18 @@
* @ingroup views_relationship_handlers * @ingroup views_relationship_handlers
*/ */
class views_handler_relationship extends views_handler { class views_handler_relationship extends views_handler {
/** /**
* Init handler to let relationships live on tables other than * Let relationships live on tables other than the table they operate on.
* the table they operate on.
*/ */
function init(&$view, &$options) { public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
if (isset($this->definition['relationship table'])) { if (isset($this->definition['relationship table'])) {
$this->table = $this->definition['relationship table']; $this->table = $this->definition['relationship table'];
} }
if (isset($this->definition['relationship field'])) { if (isset($this->definition['relationship field'])) {
// Set both real_field and field so custom handler // Set both real_field and field so custom handler can rely on the old
// can rely on the old field value. // field value.
$this->real_field = $this->field = $this->definition['relationship field']; $this->real_field = $this->field = $this->definition['relationship field'];
} }
} }
@ -55,18 +54,22 @@ class views_handler_relationship extends views_handler {
/** /**
* Get this field's label. * Get this field's label.
*/ */
function label() { public function label() {
if (!isset($this->options['label'])) { if (!isset($this->options['label'])) {
return $this->ui_name(); return $this->ui_name();
} }
return $this->options['label']; return $this->options['label'];
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
// Relationships definitions should define a default label, but if they aren't get another default value. // Relationships definitions should define a default label, but if they
// aren't get another default value.
if (!empty($this->definition['label'])) { if (!empty($this->definition['label'])) {
$label = $this->definition['label']; $label = $this->definition['label'];
} }
@ -81,10 +84,9 @@ class views_handler_relationship extends views_handler {
} }
/** /**
* Default options form that provides the label widget that all fields * Provide the label widget that all fields should have.
* should have.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['label'] = array( $form['label'] = array(
'#type' => 'textfield', '#type' => 'textfield',
@ -105,7 +107,7 @@ class views_handler_relationship extends views_handler {
/** /**
* Called to implement a relationship in a query. * Called to implement a relationship in a query.
*/ */
function query() { public function query() {
// Figure out what base table this relationship brings to the party. // Figure out what base table this relationship brings to the party.
$table_data = views_fetch_data($this->definition['base']); $table_data = views_fetch_data($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field']; $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
@ -126,7 +128,7 @@ class views_handler_relationship extends views_handler {
} }
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
$join = new $def['join_handler']; $join = new $def['join_handler']();
} }
else { else {
$join = new views_join(); $join = new views_join();
@ -137,7 +139,7 @@ class views_handler_relationship extends views_handler {
$join->construct(); $join->construct();
$join->adjusted = TRUE; $join->adjusted = TRUE;
// use a short alias for this: // Use a short alias for this.
$alias = $def['table'] . '_' . $this->table; $alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
@ -152,9 +154,10 @@ class views_handler_relationship extends views_handler {
/** /**
* You can't groupby a relationship. * You can't groupby a relationship.
*/ */
function use_group_by() { public function use_group_by() {
return FALSE; return FALSE;
} }
} }
/** /**
@ -163,22 +166,44 @@ class views_handler_relationship extends views_handler {
* @ingroup views_relationship_handlers * @ingroup views_relationship_handlers
*/ */
class views_handler_relationship_broken extends views_handler_relationship { class views_handler_relationship_broken extends views_handler_relationship {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query() { /* No query to run */ } * {@inheritdoc}
function options_form(&$form, &$form_state) { */
public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query() {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item description">' . 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.') . '</div>', '#markup' => '<div class="form-item description">' . 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.') . '</div>',
); );
} }
/** /**
* Determine if the handler is considered 'broken' * {@inheritdoc}
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }
/** /**

View File

@ -2,11 +2,12 @@
/** /**
* @file * @file
* Relationship for groupwise maximum handler. * Definition of views_handler_relationship_groupwise_max.
*/ */
/** /**
* Relationship handler that allows a groupwise maximum of the linked in table. * Relationship handler that allows a groupwise maximum of the linked in table.
*
* For a definition, see: * For a definition, see:
* http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html * http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html
* In lay terms, instead of joining to get all matching records in the linked * In lay terms, instead of joining to get all matching records in the linked
@ -58,7 +59,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
/** /**
* Defines default values for options. * Defines default values for options.
*/ */
function option_definition() { public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['subquery_sort'] = array('default' => NULL); $options['subquery_sort'] = array('default' => NULL);
@ -72,10 +73,11 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
} }
/** /**
* Extends the relationship's basic options, allowing the user to pick * Extends the relationship's basic options.
* a sort and an order for it. *
* Allows the user to pick a sort and an order for it.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Get the sorts that apply to our base. // Get the sorts that apply to our base.
@ -92,7 +94,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
'#default_value' => !empty($this->options['subquery_sort']) ? $this->options['subquery_sort'] : $this->definition['base'] . '.' . $base_table_data['table']['base']['field'], '#default_value' => !empty($this->options['subquery_sort']) ? $this->options['subquery_sort'] : $this->definition['base'] . '.' . $base_table_data['table']['base']['field'],
'#options' => $sort_options, '#options' => $sort_options,
'#description' => theme('advanced_help_topic', array('module' => 'views', 'topic' => 'relationship-representative')) . '#description' => theme('advanced_help_topic', array('module' => 'views', 'topic' => 'relationship-representative')) .
t("The sort criteria is applied to the data brought in by the relationship to determine how a representative item is obtained for each row. For example, to show the most recent node for each user, pick 'Content: Updated date'."), t("The sort criteria is applied to the data brought in by the relationship to determine how a representative item is obtained for each row. For example, to show the most recent node for each user, pick 'Content: Updated date'."),
); );
$form['subquery_order'] = array( $form['subquery_order'] = array(
@ -110,8 +112,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
'#default_value' => $this->options['subquery_namespace'], '#default_value' => $this->options['subquery_namespace'],
); );
// WIP: This stuff doesn't work yet: namespacing issues.
// WIP: This stuff doens't work yet: namespacing issues.
// A list of suitable views to pick one as the subview. // A list of suitable views to pick one as the subview.
$views = array('' => '<none>'); $views = array('' => '<none>');
$all_views = views_get_all_views(); $all_views = views_get_all_views();
@ -120,7 +121,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
// - base must the base that our relationship joins towards // - base must the base that our relationship joins towards
// - must have fields. // - must have fields.
if ($view->base_table == $this->definition['base'] && !empty($view->display['default']->display_options['fields'])) { if ($view->base_table == $this->definition['base'] && !empty($view->display['default']->display_options['fields'])) {
// TODO: check the field is the correct sort? // @todo check the field is the correct sort?
// or let users hang themselves at this stage and check later? // or let users hang themselves at this stage and check later?
if ($view->type == 'Default') { if ($view->type == 'Default') {
$views[t('Default Views')][$view->name] = $view->name; $views[t('Default Views')][$view->name] = $view->name;
@ -152,10 +153,11 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
* *
* We use this to obtain our subquery SQL. * We use this to obtain our subquery SQL.
*/ */
function get_temporary_view() { public function get_temporary_view() {
views_include('view'); views_include('view');
$view = new view(); $view = new view();
$view->vid = 'new'; // @todo: what's this? // @todo What's this?
$view->vid = 'new';
$view->base_table = $this->definition['base']; $view->base_table = $this->definition['base'];
$view->add_display('default'); $view->add_display('default');
return $view; return $view;
@ -164,7 +166,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
/** /**
* When the form is submitted, take sure to clear the subquery string cache. * When the form is submitted, take sure to clear the subquery string cache.
*/ */
function options_form_submit(&$form, &$form_state) { public function options_form_submit(&$form, &$form_state) {
$cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id']; $cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id'];
cache_clear_all($cid, 'cache_views_data'); cache_clear_all($cid, 'cache_views_data');
} }
@ -175,18 +177,19 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
* generate the subquery when the options are saved, rather than when the view * generate the subquery when the options are saved, rather than when the view
* is run. This saves considerable time. * is run. This saves considerable time.
* *
* @param $options * @param array $options
* An array of options: * An array of options that contains the following items:
* - subquery_sort: the id of a views sort. * - subquery_sort: the id of a views sort.
* - subquery_order: either ASC or DESC. * - subquery_order: either ASC or DESC.
* @return *
* @return string
* The subquery SQL string, ready for use in the main query. * The subquery SQL string, ready for use in the main query.
*/ */
function left_query($options) { public function left_query($options) {
// Either load another view, or create one on the fly. // Either load another view, or create one on the fly.
if ($options['subquery_view']) { if ($options['subquery_view']) {
$temp_view = views_get_view($options['subquery_view']); $temp_view = views_get_view($options['subquery_view']);
// Remove all fields from default display // Remove all fields from default display.
unset($temp_view->display['default']->display_options['fields']); unset($temp_view->display['default']->display_options['fields']);
} }
else { else {
@ -195,18 +198,14 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
$temp_view = $this->get_temporary_view(); $temp_view = $this->get_temporary_view();
// Add the sort from the options to the default display. // Add the sort from the options to the default display.
// This is broken, in that the sort order field also gets added as a list($sort_table, $sort_field) = explode('.', $options['subquery_sort']);
// select field. See http://drupal.org/node/844910.
// We work around this further down.
$sort = $options['subquery_sort'];
list($sort_table, $sort_field) = explode('.', $sort);
$sort_options = array('order' => $options['subquery_order']); $sort_options = array('order' => $options['subquery_order']);
$temp_view->add_item('default', 'sort', $sort_table, $sort_field, $sort_options); $temp_view->add_item('default', 'sort', $sort_table, $sort_field, $sort_options);
} }
// Get the namespace string. // Get the namespace string.
$temp_view->namespace = (!empty($options['subquery_namespace'])) ? '_'. $options['subquery_namespace'] : '_INNER'; $temp_view->namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : '_INNER';
$this->subquery_namespace = (!empty($options['subquery_namespace'])) ? '_'. $options['subquery_namespace'] : 'INNER'; $this->subquery_namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : 'INNER';
// The value we add here does nothing, but doing this adds the right tables // The value we add here does nothing, but doing this adds the right tables
// and puts in a WHERE clause with a placeholder we can grab later. // and puts in a WHERE clause with a placeholder we can grab later.
@ -217,14 +216,16 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
$base_field = $views_data['table']['base']['field']; $base_field = $views_data['table']['base']['field'];
$temp_view->add_item('default', 'field', $this->definition['base'], $this->definition['field']); $temp_view->add_item('default', 'field', $this->definition['base'], $this->definition['field']);
// Add the correct argument for our relationship's base // Add the correct argument for our relationship's base ie the "how to get
// ie the 'how to get back to base' argument. // back to base" argument; the relationship definition defines which one to
// The relationship definition tells us which one to use. // use.
$temp_view->add_item( $temp_view->add_item(
'default', 'default',
'argument', 'argument',
$this->definition['argument table'], // eg 'term_node', // For example, 'term_node',
$this->definition['argument field'] // eg 'tid' $this->definition['argument table'],
// For example, 'tid'.
$this->definition['argument field']
); );
// Build the view. The creates the query object and produces the query // Build the view. The creates the query object and produces the query
@ -235,7 +236,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
// somewhat so we can get the SQL query from it. // somewhat so we can get the SQL query from it.
$subquery = $temp_view->build_info['query']; $subquery = $temp_view->build_info['query'];
// Workaround until http://drupal.org/node/844910 is fixed: // Workaround until http://drupal.org/node/844910 is fixed.
// Remove all fields from the SELECT except the base id. // Remove all fields from the SELECT except the base id.
$fields =& $subquery->getFields(); $fields =& $subquery->getFields();
foreach (array_keys($fields) as $field_name) { foreach (array_keys($fields) as $field_name) {
@ -245,8 +246,8 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
} }
} }
// Make every alias in the subquery safe within the outer query by // Make every alias in the subquery safe within the outer query by appending
// appending a namespace to it, '_inner' by default. // a namespace to it, '_inner' by default.
$tables =& $subquery->getTables(); $tables =& $subquery->getTables();
foreach (array_keys($tables) as $table_name) { foreach (array_keys($tables) as $table_name) {
$tables[$table_name]['alias'] .= $this->subquery_namespace; $tables[$table_name]['alias'] .= $this->subquery_namespace;
@ -264,32 +265,49 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
$where =& $subquery->conditions(); $where =& $subquery->conditions();
$this->alter_subquery_condition($subquery, $where); $this->alter_subquery_condition($subquery, $where);
// Not sure why, but our sort order clause doesn't have a table. // Not sure why, but our sort order clause doesn't have a table.
// TODO: the call to add_item() above to add the sort handler is probably // @todo The call to add_item() above to add the sort handler is probably
// wrong -- needs attention from someone who understands it. // wrong -- needs attention from someone who understands it.
// In the meantime, this works, but with a leap of faith... // In the meantime, this works, but with a leap of faith.
$orders =& $subquery->getOrderBy(); $orders =& $subquery->getOrderBy();
$orders_tmp = array();
foreach ($orders as $order_key => $order) { foreach ($orders as $order_key => $order) {
// But if we're using a whole view, we don't know what we have! // Until http://drupal.org/node/844910 is fixed, $order_key is a field
if ($options['subquery_view']) { // alias from SELECT. De-alias it using the View object.
list($sort_table, $sort_field) = explode('.', $order_key); $sort_table = $temp_view->query->fields[$order_key]['table'];
} $sort_field = $temp_view->query->fields[$order_key]['field'];
$orders[$sort_table . $this->subquery_namespace . '.' . $sort_field] = $order; $orders_tmp[$sort_table . $this->subquery_namespace . '.' . $sort_field] = $order;
unset($orders[$order_key]);
} }
$orders = $orders_tmp;
// The query we get doesn't include the LIMIT, so add it here. // The query we get doesn't include the LIMIT, so add it here.
$subquery->range(0, 1); $subquery->range(0, 1);
// Clone the query object to force recompilation of the underlying where and
// having objects on the next step.
$subquery = clone $subquery;
// Add in Views Query Substitutions such as ***CURRENT_TIME***.
views_query_views_alter($subquery);
// Extract the SQL the temporary view built. // Extract the SQL the temporary view built.
$subquery_sql = $subquery->__toString(); $subquery_sql = $subquery->__toString();
// Replace the placeholder with the outer, correlated field. // Replace subquery argument placeholders.
// Eg, change the placeholder ':users_uid' into the outer field 'users.uid'. $quoted = $subquery->getArguments();
// We have to work directly with the SQL, because putting a name of a field $connection = Database::getConnection();
// into a SelectQuery that it does not recognize (because it's outer) just foreach ($quoted as $key => $val) {
// makes it treat it as a string. if (is_array($val)) {
$outer_placeholder = ':' . str_replace('.', '_', $this->definition['outer field']); $quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
$subquery_sql = str_replace($outer_placeholder, $this->definition['outer field'], $subquery_sql); }
// If the correlated placeholder has been located, replace it with the
// outer field name.
elseif ($val === '**CORRELATED**') {
$quoted[$key] = $this->definition['outer field'];
}
else {
$quoted[$key] = $connection->quote($val);
}
}
$subquery_sql = strtr($subquery_sql, $quoted);
return $subquery_sql; return $subquery_sql;
} }
@ -301,7 +319,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
* *
* (Though why is the condition we get in a simple query 3 levels deep???) * (Though why is the condition we get in a simple query 3 levels deep???)
*/ */
function alter_subquery_condition(QueryAlterableInterface $query, &$conditions) { public function alter_subquery_condition(QueryAlterableInterface $query, &$conditions) {
foreach ($conditions as $condition_id => &$condition) { foreach ($conditions as $condition_id => &$condition) {
// Skip the #conjunction element. // Skip the #conjunction element.
if (is_numeric($condition_id)) { if (is_numeric($condition_id)) {
@ -321,7 +339,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
* *
* Turns 'foo.bar' into 'foo_NAMESPACE.bar'. * Turns 'foo.bar' into 'foo_NAMESPACE.bar'.
*/ */
function condition_namespace($string) { public function condition_namespace($string) {
return str_replace('.', $this->subquery_namespace . '.', $string); return str_replace('.', $this->subquery_namespace . '.', $string);
} }
@ -330,7 +348,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
* This is mostly a copy of our parent's query() except for this bit with * This is mostly a copy of our parent's query() except for this bit with
* the join class. * the join class.
*/ */
function query() { public function query() {
// Figure out what base table this relationship brings to the party. // Figure out what base table this relationship brings to the party.
$table_data = views_fetch_data($this->definition['base']); $table_data = views_fetch_data($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field']; $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
@ -374,9 +392,10 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
$join->construct(); $join->construct();
$join->adjusted = TRUE; $join->adjusted = TRUE;
// use a short alias for this: // Use a short alias for this.
$alias = $def['table'] . '_' . $this->table; $alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
} }
} }

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* @todo. * Definition of views_handler_sort.
*/ */
/** /**
@ -21,18 +21,23 @@ class views_handler_sort extends views_handler {
/** /**
* Determine if a sort can be exposed. * Determine if a sort can be exposed.
*/ */
function can_expose() { return TRUE; } public function can_expose() {
return TRUE;
}
/** /**
* Called to add the sort to a query. * Called to add the sort to a query.
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
// Add the field. // Add the field.
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['order'] = array('default' => 'ASC'); $options['order'] = array('default' => 'ASC');
@ -48,7 +53,7 @@ class views_handler_sort extends views_handler {
/** /**
* Display whether or not the sort order is ascending or descending * Display whether or not the sort order is ascending or descending
*/ */
function admin_summary() { public function admin_summary() {
if (!empty($this->options['exposed'])) { if (!empty($this->options['exposed'])) {
return t('Exposed'); return t('Exposed');
} }
@ -57,18 +62,17 @@ class views_handler_sort extends views_handler {
case 'asc': case 'asc':
default: default:
return t('asc'); return t('asc');
break;
case 'DESC'; case 'DESC';
case 'desc'; case 'desc';
return t('desc'); return t('desc');
break;
} }
} }
/** /**
* Basic options for all sort criteria * Basic options for all sort criteria
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
if ($this->can_expose()) { if ($this->can_expose()) {
$this->show_expose_button($form, $form_state); $this->show_expose_button($form, $form_state);
@ -84,11 +88,11 @@ class views_handler_sort extends views_handler {
/** /**
* Shortcut to display the expose/hide button. * Shortcut to display the expose/hide button.
*/ */
function show_expose_button(&$form, &$form_state) { public function show_expose_button(&$form, &$form_state) {
$form['expose_button'] = array( $form['expose_button'] = array(
'#prefix' => '<div class="views-expose clearfix">', '#prefix' => '<div class="views-expose clearfix">',
'#suffix' => '</div>', '#suffix' => '</div>',
// Should always come first // Should always come first.
'#weight' => -1000, '#weight' => -1000,
); );
@ -131,9 +135,9 @@ class views_handler_sort extends views_handler {
} }
/** /**
* Simple validate handler * Simple validate handler.
*/ */
function options_validate(&$form, &$form_state) { public function options_validate(&$form, &$form_state) {
$this->sort_validate($form, $form_state); $this->sort_validate($form, $form_state);
if (!empty($this->options['exposed'])) { if (!empty($this->options['exposed'])) {
$this->expose_validate($form, $form_state); $this->expose_validate($form, $form_state);
@ -142,10 +146,12 @@ class views_handler_sort extends views_handler {
} }
/** /**
* Simple submit handler * Simple submit handler.
*/ */
function options_submit(&$form, &$form_state) { public function options_submit(&$form, &$form_state) {
unset($form_state['values']['expose_button']); // don't store this. // Don't store this.
unset($form_state['values']['expose_button']);
$this->sort_submit($form, $form_state); $this->sort_submit($form, $form_state);
if (!empty($this->options['exposed'])) { if (!empty($this->options['exposed'])) {
$this->expose_submit($form, $form_state); $this->expose_submit($form, $form_state);
@ -155,7 +161,7 @@ class views_handler_sort extends views_handler {
/** /**
* Shortcut to display the value form. * Shortcut to display the value form.
*/ */
function show_sort_form(&$form, &$form_state) { public function show_sort_form(&$form, &$form_state) {
$options = $this->sort_options(); $options = $this->sort_options();
if (!empty($options)) { if (!empty($options)) {
$form['order'] = array( $form['order'] = array(
@ -166,22 +172,34 @@ class views_handler_sort extends views_handler {
} }
} }
function sort_validate(&$form, &$form_state) { } /**
* {@inheritdoc}
*/
public function sort_validate(&$form, &$form_state) {
}
function sort_submit(&$form, &$form_state) { } /**
* {@inheritdoc}
*/
public function sort_submit(&$form, &$form_state) {
}
/** /**
* Provide a list of options for the default sort form. * Provide a list of options for the default sort form.
* Should be overridden by classes that don't override sort_form *
* Should be overridden by classes that don't override sort_form.
*/ */
function sort_options() { public function sort_options() {
return array( return array(
'ASC' => t('Sort ascending'), 'ASC' => t('Sort ascending'),
'DESC' => t('Sort descending'), 'DESC' => t('Sort descending'),
); );
} }
function expose_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function expose_form(&$form, &$form_state) {
// #flatten will move everything from $form['expose'][$key] to $form[$key] // #flatten will move everything from $form['expose'][$key] to $form[$key]
// prior to rendering. That's why the pre_render for it needs to run first, // prior to rendering. That's why the pre_render for it needs to run first,
// so that when the next pre_render (the one for fieldsets) runs, it gets // so that when the next pre_render (the one for fieldsets) runs, it gets
@ -196,18 +214,19 @@ class views_handler_sort extends views_handler {
'#required' => TRUE, '#required' => TRUE,
'#size' => 40, '#size' => 40,
'#weight' => -1, '#weight' => -1,
); );
} }
/** /**
* Provide default options for exposed sorts. * Provide default options for exposed sorts.
*/ */
function expose_options() { public function expose_options() {
$this->options['expose'] = array( $this->options['expose'] = array(
'order' => $this->options['order'], 'order' => $this->options['order'],
'label' => $this->definition['title'], 'label' => $this->definition['title'],
); );
} }
} }
/** /**
@ -216,22 +235,44 @@ class views_handler_sort extends views_handler {
* @ingroup views_sort_handlers * @ingroup views_sort_handlers
*/ */
class views_handler_sort_broken extends views_handler_sort { class views_handler_sort_broken extends views_handler_sort {
function ui_name($short = FALSE) {
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return t('Broken/missing handler'); return t('Broken/missing handler');
} }
function ensure_my_table() { /* No table to ensure! */ } /**
function query($group_by = FALSE) { /* No query to run */ } * {@inheritdoc}
function options_form(&$form, &$form_state) { */
public function ensure_my_table() {
// No table to ensure!
}
/**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item description">' . 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.') . '</div>', '#markup' => '<div class="form-item description">' . 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.') . '</div>',
); );
} }
/** /**
* Determine if the handler is considered 'broken' * Determine if the handler is considered 'broken'.
*/ */
function broken() { return TRUE; } public function broken() {
return TRUE;
}
} }

View File

@ -14,7 +14,11 @@
* @ingroup views_sort_handlers * @ingroup views_sort_handlers
*/ */
class views_handler_sort_date extends views_handler_sort { class views_handler_sort_date extends views_handler_sort {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['granularity'] = array('default' => 'second'); $options['granularity'] = array('default' => 'second');
@ -22,7 +26,10 @@ class views_handler_sort_date extends views_handler_sort {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['granularity'] = array( $form['granularity'] = array(
@ -42,27 +49,32 @@ class views_handler_sort_date extends views_handler_sort {
} }
/** /**
* Called to add the sort to a query. * {@inheritdoc}
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
switch ($this->options['granularity']) { switch ($this->options['granularity']) {
case 'second': case 'second':
default: default:
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
return; return;
case 'minute': case 'minute':
$formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field"); $formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field");
break; break;
case 'hour': case 'hour':
$formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field"); $formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field");
break; break;
case 'day': case 'day':
$formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field"); $formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field");
break; break;
case 'month': case 'month':
$formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field"); $formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field");
break; break;
case 'year': case 'year':
$formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field"); $formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field");
break; break;
@ -71,4 +83,5 @@ class views_handler_sort_date extends views_handler_sort {
// Add the field. // Add the field.
$this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']); $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']);
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_sort_handlers * @ingroup views_sort_handlers
*/ */
class views_handler_sort_group_by_numeric extends views_handler_sort { class views_handler_sort_group_by_numeric extends views_handler_sort {
function init(&$view, &$options) {
/**
* {@inheritdoc}
*/
public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
// Initialize the original handler. // Initialize the original handler.
@ -20,9 +24,9 @@ class views_handler_sort_group_by_numeric extends views_handler_sort {
} }
/** /**
* Called to add the field to a query. * {@inheritdoc}
*/ */
function query() { public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$params = array( $params = array(
@ -32,7 +36,11 @@ class views_handler_sort_group_by_numeric extends views_handler_sort {
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order'], NULL, $params); $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order'], NULL, $params);
} }
function ui_name($short = FALSE) { /**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return $this->get_field(parent::ui_name($short)); return $this->get_field(parent::ui_name($short));
} }
} }

View File

@ -17,13 +17,20 @@
* @ingroup views_sort_handlers * @ingroup views_sort_handlers
*/ */
class views_handler_sort_menu_hierarchy extends views_handler_sort { class views_handler_sort_menu_hierarchy extends views_handler_sort {
function option_definition() {
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['sort_within_level'] = array('default' => FALSE); $options['sort_within_level'] = array('default' => FALSE);
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['sort_within_level'] = array( $form['sort_within_level'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
@ -33,7 +40,10 @@ class views_handler_sort_menu_hierarchy extends views_handler_sort {
); );
} }
function query() { /**
* {@inheritdoc}
*/
public function query() {
$this->ensure_my_table(); $this->ensure_my_table();
$max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH; $max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH;
for ($i = 1; $i <= $max_depth; ++$i) { for ($i = 1; $i <= $max_depth; ++$i) {
@ -51,4 +61,5 @@ class views_handler_sort_menu_hierarchy extends views_handler_sort {
$this->query->add_orderby($this->table_alias, $this->field . $i, $this->options['order']); $this->query->add_orderby($this->table_alias, $this->field . $i, $this->options['order']);
} }
} }
} }

View File

@ -11,12 +11,20 @@
* @ingroup views_sort_handlers * @ingroup views_sort_handlers
*/ */
class views_handler_sort_random extends views_handler_sort { class views_handler_sort_random extends views_handler_sort {
function query() {
/**
* {@inheritdoc}
*/
public function query() {
$this->query->add_orderby('rand'); $this->query->add_orderby('rand');
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$form['order']['#access'] = FALSE; $form['order']['#access'] = FALSE;
} }
} }

View File

@ -4,8 +4,9 @@ As a consequence, it *always* thinks the value was submitted, even if it was not
<pre> <pre>
&lt;?php &lt;?php
if (empty($form_state['view']->exposed_input[$identifier])) . if (empty($form_state['view']->exposed_input[$identifier])) {
{ $form_state['input'][$identifier] = $default_value; } $form_state['input'][$identifier] = $default_value;
}
?&gt; ?&gt;
</pre> </pre>
@ -18,10 +19,10 @@ To do this, I used the following function, where geoip_redirect_get_tid() loads
<pre> <pre>
&lt;?php &lt;?php
function MODULENAME_form_views_exposed_form_alter(&$form, $form_state) { function MODULENAME_form_views_exposed_form_alter(&$form, $form_state) {
if(strpos($form['#id'], 'volunteer-directory') !== FALSE) { if (strpos($form['#id'], 'volunteer-directory') !== FALSE) {
$city_tid = geoip_redirect_get_tid(); $city_tid = geoip_redirect_get_tid();
if(is_numeric($city_tid) && $city_tid != 7660) { if (is_numeric($city_tid) && $city_tid != 7660) {
if (empty($form_state['view']->exposed_input['tid'])) { if (empty($form_state['view']->exposed_input['tid'])) {
$form_state['input']['tid'] = $city_tid; $form_state['input']['tid'] = $city_tid;
} }
} }

View File

@ -40,7 +40,7 @@ Below is the contents of a simple node_example.views.inc file that allows you to
* @endcode * @endcode
*/ */
function node_example_views_data() { function node_example_views_data() {
// Basic table information. // Basic table information.
// ---------------------------------------------------------------- // ----------------------------------------------------------------

View File

@ -169,8 +169,10 @@ Each field is described in the view data with an array, keyed to the database na
<pre> <pre>
$data['node']['nid'] = array( $data['node']['nid'] = array(
// The item it appears as on the UI,
'title' =&gt; t('Nid'), 'title' =&gt; t('Nid'),
'help' =&gt; t('The node ID of the node.'), // The help that appears on the UI, // The help that appears on the UI,
'help' =&gt; t('The node ID of the node.'),
// Information for displaying the nid // Information for displaying the nid
'field' =&gt; array( 'field' =&gt; array(
'handler' =&gt; 'views_handler_field_node', 'handler' =&gt; 'views_handler_field_node',
@ -179,7 +181,8 @@ $data['node']['nid'] = array(
// Information for accepting a nid as an argument // Information for accepting a nid as an argument
'argument' =&gt; array( 'argument' =&gt; array(
'handler' =&gt; 'views_handler_argument_node_nid', 'handler' =&gt; 'views_handler_argument_node_nid',
'name field' =&gt; 'title', // the field to display in the summary. // The field to display in the summary.
'name field' =&gt; 'title',
'numeric' =&gt; TRUE, 'numeric' =&gt; TRUE,
'validate type' =&gt; 'nid', 'validate type' =&gt; 'nid',
), ),

View File

@ -113,9 +113,9 @@ The views_handler class got two new functions:
/** /**
* Get the value that's supposed to be rendered. * Get the value that's supposed to be rendered.
* *
* @param $values * @param object $values
* An object containing all retrieved values. * An object containing all retrieved values.
* @param $field * @param string $field
* Optional name of the field where the value is stored. * Optional name of the field where the value is stored.
*/ */
function get_value($values, $field = NULL) { function get_value($values, $field = NULL) {
@ -128,9 +128,9 @@ function get_value($values, $field = NULL) {
/** /**
* Sanitize the value for output. * Sanitize the value for output.
* *
* @param $value * @param string $value
* The value being rendered. * The value being rendered.
* @param $type * @param string $type
* The type of sanitization needed. If not provided, check_plain() is used. * The type of sanitization needed. If not provided, check_plain() is used.
*/ */
function sanitize_value($value, $type = NULL) { function sanitize_value($value, $type = NULL) {
@ -138,9 +138,11 @@ function sanitize_value($value, $type = NULL) {
case 'xss': case 'xss':
$value = filter_xss($value); $value = filter_xss($value);
break; break;
case 'url': case 'url':
$value = check_url($value); $value = check_url($value);
break; break;
default: default:
$value = check_plain($value); $value = check_plain($value);
break; break;

View File

@ -10,9 +10,9 @@ easiest way is to use the function <strong>views_embed_view()</strong>:
* solution and doesn't really offer a lot of options, but breaking the function * 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. * apart is pretty easy, and this provides a worthwhile guide to doing so.
* *
* @param $name * @param string $name
* The name of the view to embed. * The name of the view to embed.
* @param $display_id * @param string $display_id
* The display id to embed. If unsure, use 'default', as it will always be * The display id to embed. If unsure, use 'default', as it will always be
* valid. But things like 'page' or 'block' should work here. * valid. But things like 'page' or 'block' should work here.
* @param ... * @param ...

View File

@ -13,7 +13,7 @@ This section originally stems from <a href="http://drupal.org/node/346662">this
Some modules may add PHP improperly, disrupting normal jQuery operation. Errors may look like Some modules may add PHP improperly, disrupting normal jQuery operation. Errors may look like
<code> <code>
<? session_module_name("files"); ?>{ "default": "default" } <?php session_module_name("files"); ?>{ "default": "default" }
</code> </code>
This can also be a server configuration issue. In one case, this was solved by commenting out This can also be a server configuration issue. In one case, this was solved by commenting out

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,8 @@ function views_ajax() {
$commands = array(); $commands = array();
// Remove all of this stuff from $_GET so it doesn't end up in pagers and tablesort URLs. // Remove all of this stuff from $_GET so it doesn't end up in pagers and
// tablesort URLs.
foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', 'ajax_html_ids', 'ajax_page_state') as $key) { foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', 'ajax_html_ids', 'ajax_page_state') as $key) {
if (isset($_GET[$key])) { if (isset($_GET[$key])) {
unset($_GET[$key]); unset($_GET[$key]);
@ -40,17 +41,17 @@ function views_ajax() {
// Load the view. // Load the view.
$view = views_get_view($name); $view = views_get_view($name);
if ($view && $view->access($display_id)) { if ($view && $view->access($display_id) && $view->set_display($display_id) && $view->display_handler->use_ajax()) {
// Fix 'q' for paging. // Fix 'q' for paging.
if (!empty($path)) { if (!empty($path)) {
$_GET['q'] = $path; $_GET['q'] = $path;
} }
// If page parameter is in the $_POST exclude it from $_GET, // If page parameter is in the $_POST exclude it from $_GET, otherwise
// otherwise support views_ajax requests using $_GET. // support views_ajax requests using $_GET.
$exclude = isset($_POST['page']) ? array('page') : array(); $exclude = isset($_POST['page']) ? array('page') : array();
// Add all $_POST data to $_GET as many things, // Add all $_POST data to $_GET as many things, such as tablesorts,
// such as tablesorts, exposed filters and paging assume $_GET. // exposed filters and paging assume $_GET.
$_GET = $_POST + drupal_get_query_parameters($_GET, $exclude); $_GET = $_POST + drupal_get_query_parameters($_GET, $exclude);
// Overwrite the destination. // Overwrite the destination.
@ -81,14 +82,14 @@ function views_ajax() {
/** /**
* Creates a Drupal AJAX 'viewsSetForm' command. * Creates a Drupal AJAX 'viewsSetForm' command.
* *
* @param $output * @param string $output
* The form to display in the modal. * The form to display in the modal.
* @param $title * @param string $title
* The title. * The title.
* @param $url * @param string $url
* An optional URL. * An optional URL.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_set_form($output, $title, $url = NULL) { function views_ajax_command_set_form($output, $title, $url = NULL) {
@ -106,7 +107,7 @@ function views_ajax_command_set_form($output, $title, $url = NULL) {
/** /**
* Creates a Drupal AJAX 'viewsDismissForm' command. * Creates a Drupal AJAX 'viewsDismissForm' command.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_dismiss_form() { function views_ajax_command_dismiss_form() {
@ -119,8 +120,8 @@ function views_ajax_command_dismiss_form() {
/** /**
* Creates a Drupal AJAX 'viewsHilite' command. * Creates a Drupal AJAX 'viewsHilite' command.
* *
* @param $selector * @param string $selector
* The selector to highlight * The selector to highlight.
* *
* @return * @return
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
@ -135,14 +136,14 @@ function views_ajax_command_hilite($selector) {
/** /**
* Creates a Drupal AJAX 'addTab' command. * Creates a Drupal AJAX 'addTab' command.
* *
* @param $id * @param string $id
* The DOM ID. * The DOM ID.
* @param $title * @param string $title
* The title. * The title.
* @param $body * @param string $body
* The body. * The body.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_add_tab($id, $title, $body) { function views_ajax_command_add_tab($id, $title, $body) {
@ -158,7 +159,7 @@ function views_ajax_command_add_tab($id, $title, $body) {
/** /**
* Scroll to top of the current view. * Scroll to top of the current view.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_scroll_top($selector) { function views_ajax_command_scroll_top($selector) {
@ -175,7 +176,7 @@ function views_ajax_command_scroll_top($selector) {
* @param bool $changed * @param bool $changed
* Whether of not the view has changed. * Whether of not the view has changed.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_show_buttons($changed) { function views_ajax_command_show_buttons($changed) {
@ -189,7 +190,7 @@ function views_ajax_command_show_buttons($changed) {
/** /**
* Trigger the Views live preview. * Trigger the Views live preview.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_trigger_preview() { function views_ajax_command_trigger_preview() {
@ -202,7 +203,7 @@ function views_ajax_command_trigger_preview() {
/** /**
* Replace the page title. * Replace the page title.
* *
* @return * @return array
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_command_replace_title($title) { function views_ajax_command_replace_title($title) {
@ -216,6 +217,12 @@ function views_ajax_command_replace_title($title) {
/** /**
* Return an AJAX error. * Return an AJAX error.
*
* @param string $message
* The message to display.
*
* @return array
* An array suitable for use with the ajax_render() function.
*/ */
function views_ajax_error($message) { function views_ajax_error($message) {
$commands = array(); $commands = array();
@ -225,6 +232,7 @@ function views_ajax_error($message) {
/** /**
* Wrapper around drupal_build_form to handle some AJAX stuff automatically. * Wrapper around drupal_build_form to handle some AJAX stuff automatically.
*
* This makes some assumptions about the client. * This makes some assumptions about the client.
*/ */
function views_ajax_form_wrapper($form_id, &$form_state) { function views_ajax_form_wrapper($form_id, &$form_state) {
@ -243,15 +251,15 @@ function views_ajax_form_wrapper($form_id, &$form_state) {
$form = drupal_build_form($form_id, $form_state); $form = drupal_build_form($form_id, $form_state);
$output = drupal_render($form); $output = drupal_render($form);
// These forms have the title built in, so set the title here: // These forms have the title built in, so set the title here.
if (empty($form_state['ajax']) && !empty($form_state['title'])) { if (empty($form_state['ajax']) && !empty($form_state['title'])) {
drupal_set_title($form_state['title']); drupal_set_title($form_state['title']);
drupal_add_css(drupal_get_path('module', 'views_ui') . '/css/views-admin.css'); drupal_add_css(drupal_get_path('module', 'views_ui') . '/css/views-admin.css');
} }
if (!empty($form_state['ajax']) && (empty($form_state['executed']) || !empty($form_state['rerender']))) { if (!empty($form_state['ajax']) && (empty($form_state['executed']) || !empty($form_state['rerender']))) {
// If the form didn't execute and we're using ajax, build up a // If the form didn't execute and we're using ajax, build up a AJAX command
// Ajax command list to execute. // list to execute.
$commands = array(); $commands = array();
$display = ''; $display = '';
@ -279,7 +287,7 @@ function views_ajax_form_wrapper($form_id, &$form_state) {
return $commands; return $commands;
} }
// These forms have the title built in, so set the title here: // These forms have the title built in, so set the title here.
if (empty($form_state['ajax']) && !empty($form_state['title'])) { if (empty($form_state['ajax']) && !empty($form_state['title'])) {
drupal_set_title($form_state['title']); drupal_set_title($form_state['title']);
} }
@ -289,13 +297,14 @@ function views_ajax_form_wrapper($form_id, &$form_state) {
/** /**
* Page callback for views user autocomplete * Page callback for views user autocomplete.
*/ */
function views_ajax_autocomplete_user($string = '') { function views_ajax_autocomplete_user($string = '') {
// The user enters a comma-separated list of user name. We only autocomplete the last name. // The user enters a comma-separated list of user name. We only autocomplete
// the last name.
$array = drupal_explode_tags($string); $array = drupal_explode_tags($string);
// Fetch last name // Fetch last name.
$last_string = trim(array_pop($array)); $last_string = trim(array_pop($array));
$matches = array(); $matches = array();
if ($last_string != '') { if ($last_string != '') {
@ -328,16 +337,16 @@ function views_ajax_autocomplete_user($string = '') {
/** /**
* Page callback for views taxonomy autocomplete. * Page callback for views taxonomy autocomplete.
* *
* @param $vid * @param int $vid
* The vocabulary id of the tags which should be returned. * The vocabulary id of the tags which should be returned.
* * @param string $tags_typed
* @param $tags_typed
* The typed string of the user. * The typed string of the user.
* *
* @see taxonomy_autocomplete() * @see taxonomy_autocomplete()
*/ */
function views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') { function views_ajax_autocomplete_taxonomy($vid, $tags_typed = '') {
// The user enters a comma-separated list of tags. We only autocomplete the last tag. // The user enters a comma-separated list of tags. We only autocomplete the
// last tag.
$tags_typed = drupal_explode_tags($tags_typed); $tags_typed = drupal_explode_tags($tags_typed);
$tag_last = drupal_strtolower(array_pop($tags_typed)); $tag_last = drupal_strtolower(array_pop($tags_typed));

View File

@ -16,8 +16,8 @@
* Analyze a review and return the results. * Analyze a review and return the results.
* *
* @return * @return
* An array of analyze results organized into arrays keyed by 'ok', * An array of analyze results organized into arrays keyed by 'ok', 'warning'
* 'warning' and 'error'. * and 'error'.
*/ */
function views_analyze_view(&$view) { function views_analyze_view(&$view) {
$view->init_display(); $view->init_display();
@ -79,12 +79,12 @@ function views_analyze_format_result($view, $messages) {
* that may be broken unless the user knows what he or she is doing, * 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. * and 'error' for items that are definitely broken are much more useful.
* *
* @param $messages * @param string $message
* The message to report. * The message to report.
* @param $type * @param string $type
* The type of message. This should be "ok", "warning" or "error". Other * 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 * values can be used but how they are treated by the output routine is
* is undefined. * undefined.
*/ */
function views_ui_analysis($message, $type = 'error') { function views_ui_analysis($message, $type = 'error') {
return array('message' => $message, 'type' => $type); return array('message' => $message, 'type' => $type);
@ -99,7 +99,7 @@ function views_ui_analysis($message, $type = 'error') {
*/ */
function views_ui_views_analyze($view) { function views_ui_views_analyze($view) {
$ret = array(); $ret = array();
// Check for something other than the default display: // Check for something other than the default display.
if (count($view->display) < 2) { 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'); $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');
} }

View File

@ -2,34 +2,36 @@
/** /**
* @file * @file
* Provides the basic object definitions used by plugins and handlers. * Definition of views_object.
*/ */
/** /**
* Basic definition for many views objects. * Provides the basic object definitions used by plugins and handlers.
*/ */
class views_object { class views_object {
/** /**
* Except for displays, options for the object will be held here. * Except for displays, options for the object will be held here.
*/ */
var $options = array(); public $options = array();
/** /**
* The top object of a view. * The top object of a view.
* *
* @var view * @var view
*/ */
var $view = NULL; public $view = NULL;
/** /**
* Handler's definition * Handler's definition.
* *
* @var array * @var array
*/ */
var $definition; public $definition;
/** /**
* Information about options for all kinds of purposes will be held here. * Information about options for all kinds of purposes will be held here.
*
* @code * @code
* 'option_name' => array( * 'option_name' => array(
* - 'default' => default value, * - 'default' => default value,
@ -52,35 +54,69 @@ class views_object {
* @see views_object::export_option_always() * @see views_object::export_option_always()
* @see views_object::unpack_translatable() * @see views_object::unpack_translatable()
*/ */
function option_definition() { return array(); } public function option_definition() {
return array();
}
/** /**
* Views handlers use a special construct function so that we can more * Collect this handler's option definition and alter them, ready for use.
* easily construct them with variable arguments. *
* @return array
* Returns the options of this handler/plugin after allowing for alters.
*
* @see hook_views_plugin_option_definition_alter()
* @see hook_views_handler_option_definition_alter()
*/ */
function construct() { $this->set_default_options(); } function altered_option_definition() {
$definition = $this->option_definition();
if (!empty($this->is_plugin)) {
// Trigger hook_views_plugin_option_definition_alter().
drupal_alter('views_plugin_option_definition', $definition, $this);
}
else {
// Trigger hook_views_handler_option_definition_alter().
drupal_alter('views_handler_option_definition', $definition, $this);
}
return $definition;
}
/** /**
* Set default options on this object. Called by the constructor in a * Views handlers use a special construct function.
* complex chain to deal with backward compatibility. *
* Allows it to more easily construct them with variable arguments.
*/
public 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.
* *
* @deprecated since views2 * @deprecated since views2
*/ */
function options(&$options) { } public function options(&$options) {
}
/** /**
* Set default options. * Set default options.
* For backward compatibility, it sends the options array; this is a *
* feature that will likely disappear at some point. * For backward compatibility, it sends the options array; this is a feature
* that will likely disappear at some point.
*/ */
function set_default_options() { public function set_default_options() {
$this->_set_option_defaults($this->options, $this->option_definition()); $this->_set_option_defaults($this->options, $this->altered_option_definition());
// Retained for complex defaults plus backward compatibility. // Retained for complex defaults plus backward compatibility.
$this->options($this->options); $this->options($this->options);
} }
function _set_option_defaults(&$storage, $options, $level = 0) { /**
*
*/
public function _set_option_defaults(&$storage, $options, $level = 0) {
foreach ($options as $option => $definition) { foreach ($options as $option => $definition) {
if (isset($definition['contains']) && is_array($definition['contains'])) { if (isset($definition['contains']) && is_array($definition['contains'])) {
$storage[$option] = array(); $storage[$option] = array();
@ -96,28 +132,28 @@ class views_object {
} }
/** /**
* Unpack options over our existing defaults, drilling down into arrays * Unpack options over our existing defaults, drilling down into arrays so
* so that defaults don't get totally blown away. * that defaults don't get totally blown away.
*/ */
function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) { public function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) {
if ($check && !is_array($options)) { if ($check && !is_array($options)) {
return; return;
} }
if (!isset($definition)) { if (!isset($definition)) {
$definition = $this->option_definition(); $definition = $this->altered_option_definition();
} }
if (!empty($this->view)) { if (!empty($this->view)) {
// Ensure we have a localization plugin. // Ensure we have a localization plugin.
$this->view->init_localization(); $this->view->init_localization();
// Set up default localization keys. Handlers and such set this for us // Set up default localization keys. Handlers and such set this for us.
if (empty($localization_keys) && isset($this->localization_keys)) { if (empty($localization_keys) && isset($this->localization_keys)) {
$localization_keys = $this->localization_keys; $localization_keys = $this->localization_keys;
} }
// but plugins don't because there isn't a common init() these days. // but plugins don't because there isn't a common init() these days.
else if (!empty($this->is_plugin) && empty($localization_keys)) { elseif (!empty($this->is_plugin) && empty($localization_keys)) {
if ($this->plugin_type != 'display') { if ($this->plugin_type != 'display') {
$localization_keys = array($this->view->current_display); $localization_keys = array($this->view->current_display);
$localization_keys[] = $this->plugin_type; $localization_keys[] = $this->plugin_type;
@ -146,9 +182,9 @@ class views_object {
$this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key))); $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key)));
} }
// Don't localize strings during editing. When editing, we need to work with // Don't localize strings during editing. When editing, we need to work
// the original data, not the translated version. // with the original data, not the translated version.
else if (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) { elseif (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) {
if (!empty($this->view) && $this->view->is_translatable()) { if (!empty($this->view) && $this->view->is_translatable()) {
// Allow other modules to make changes to the string before it's // Allow other modules to make changes to the string before it's
// sent for translation. // sent for translation.
@ -170,7 +206,7 @@ class views_object {
$storage[$key] = t($value); $storage[$key] = t($value);
} }
} }
else if ($all || !empty($definition[$key])) { elseif ($all || !empty($definition[$key])) {
$storage[$key] = $value; $storage[$key] = $value;
} }
} }
@ -179,14 +215,17 @@ class views_object {
/** /**
* Let the handler know what its full definition is. * Let the handler know what its full definition is.
*/ */
function set_definition($definition) { public function set_definition($definition) {
$this->definition = $definition; $this->definition = $definition;
if (isset($definition['field'])) { if (isset($definition['field'])) {
$this->real_field = $definition['field']; $this->real_field = $definition['field'];
} }
} }
function destroy() { /**
* Destructor.
*/
public function destroy() {
if (isset($this->view)) { if (isset($this->view)) {
unset($this->view); unset($this->view);
} }
@ -200,16 +239,22 @@ class views_object {
} }
} }
function export_options($indent, $prefix) { /**
*
*/
public function export_options($indent, $prefix) {
$output = ''; $output = '';
foreach ($this->option_definition() as $option => $definition) { foreach ($this->altered_option_definition() as $option => $definition) {
$output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array()); $output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array());
} }
return $output; return $output;
} }
function export_option($indent, $prefix, $storage, $option, $definition, $parents) { /**
*
*/
public function export_option($indent, $prefix, $storage, $option, $definition, $parents) {
// Do not export options for which we have no settings. // Do not export options for which we have no settings.
if (!isset($storage[$option])) { if (!isset($storage[$option])) {
return; return;
@ -220,7 +265,7 @@ class views_object {
return; return;
} }
// Special handling for some items // Special handling for some items.
if (method_exists($this, $definition['export'])) { if (method_exists($this, $definition['export'])) {
return $this->{$definition['export']}($indent, $prefix, $storage, $option, $definition, $parents); return $this->{$definition['export']}($indent, $prefix, $storage, $option, $definition, $parents);
} }
@ -262,7 +307,7 @@ class views_object {
/** /**
* Always exports the option, regardless of the default value. * Always exports the option, regardless of the default value.
*/ */
function export_option_always($indent, $prefix, $storage, $option, $definition, $parents) { public function export_option_always($indent, $prefix, $storage, $option, $definition, $parents) {
// If there is no default, the option will always be exported. // If there is no default, the option will always be exported.
unset($definition['default']); unset($definition['default']);
// Unset our export method to prevent recursion. // Unset our export method to prevent recursion.
@ -273,8 +318,8 @@ class views_object {
/** /**
* Unpacks each handler to store translatable texts. * Unpacks each handler to store translatable texts.
*/ */
function unpack_translatables(&$translatable, $parents = array()) { public function unpack_translatables(&$translatable, $parents = array()) {
foreach ($this->option_definition() as $option => $definition) { foreach ($this->altered_option_definition() as $option => $definition) {
$this->unpack_translatable($translatable, $this->options, $option, $definition, $parents, array()); $this->unpack_translatable($translatable, $this->options, $option, $definition, $parents, array());
} }
} }
@ -284,21 +329,21 @@ class views_object {
* *
* This function run's through all suboptions recursive. * This function run's through all suboptions recursive.
* *
* @param $translatable * @param array $translatable
* Stores all available translatable items. * Stores all available translatable items.
* @param $storage * @param array $storage
* @param $option * @param string $option
* @param $definition * @param string $definition
* @param $parents * @param array $parents
* @param $keys * @param array $keys
*/ */
function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) { public function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) {
// Do not export options for which we have no settings. // Do not export options for which we have no settings.
if (!isset($storage[$option])) { if (!isset($storage[$option])) {
return; return;
} }
// Special handling for some items // Special handling for some items.
if (isset($definition['unpack_translatable']) && method_exists($this, $definition['unpack_translatable'])) { if (isset($definition['unpack_translatable']) && method_exists($this, $definition['unpack_translatable'])) {
return $this->{$definition['unpack_translatable']}($translatable, $storage, $option, $definition, $parents, $keys); return $this->{$definition['unpack_translatable']}($translatable, $storage, $option, $definition, $parents, $keys);
} }
@ -328,8 +373,8 @@ class views_object {
if (is_array($value)) { if (is_array($value)) {
$this->unpack_translatable($translatable, $options, $key, $definition, $parents, $translation_keys); $this->unpack_translatable($translatable, $options, $key, $definition, $parents, $translation_keys);
} }
else if (!empty($definition[$key]['translatable']) && !empty($value)) { elseif (!empty($definition[$key]['translatable']) && !empty($value)) {
// Build source data and add to the array // Build source data and add to the array.
$format = NULL; $format = NULL;
if (isset($definition['format_key']) && isset($options[$definition['format_key']])) { if (isset($definition['format_key']) && isset($options[$definition['format_key']])) {
$format = $options[$definition['format_key']]; $format = $options[$definition['format_key']];
@ -342,9 +387,9 @@ class views_object {
} }
} }
} }
else if (!empty($definition['translatable']) && !empty($options)) { elseif (!empty($definition['translatable']) && !empty($options)) {
$value = $options; $value = $options;
// Build source data and add to the array // Build source data and add to the array.
$format = NULL; $format = NULL;
if (isset($definition['format_key']) && isset($storage[$definition['format_key']])) { if (isset($definition['format_key']) && isset($storage[$definition['format_key']])) {
$format = $storage[$definition['format_key']]; $format = $storage[$definition['format_key']];
@ -356,4 +401,5 @@ class views_object {
); );
} }
} }
} }

View File

@ -6,11 +6,13 @@
*/ */
/** /**
* Fetch Views' data from the cache * Fetch Views' data from the cache.
* *
* @param $move * @param string $table
* Under certain circumstances it makes sense to not get the moved table, but the old one. * @param bool $move
* One example is views_get_handler. * Under certain circumstances it makes sense to not get the moved table, but
* the old one. One example is views_get_handler.
* @param bool $reset
*/ */
function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) { function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
$cache = &drupal_static(__FUNCTION__ . '_cache'); $cache = &drupal_static(__FUNCTION__ . '_cache');
@ -100,7 +102,8 @@ function _views_fetch_data_build() {
} }
/** /**
* Links tables having an 'entity type' specified to the respective generic entity-type tables. * Links tables having an 'entity type' specified to the respective generic
* entity-type tables.
*/ */
function _views_data_process_entity_types(&$data) { function _views_data_process_entity_types(&$data) {
foreach ($data as $table_name => $table_info) { foreach ($data as $table_name => $table_info) {
@ -151,7 +154,7 @@ function _views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE)
return $cache; return $cache;
} }
elseif (!$plugin) { elseif (!$plugin) {
// Not in the if above so the else below won't run // Not in the if above so the else below won't run.
if (isset($cache[$type])) { if (isset($cache[$type])) {
return $cache[$type]; return $cache[$type];
} }
@ -169,12 +172,13 @@ function _views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE)
* *
* This is just a convenience wrapper around cache_set(). * This is just a convenience wrapper around cache_set().
* *
* @param $cid * @param string $cid
* The cache ID of the data to store. * The cache ID of the data to store.
* @param $data * @param mixed $data
* The data to store in the cache. Complex data types will be automatically serialized before insertion. * The data to store in the cache. Complex data types will be automatically
* Strings will be stored as plain text and not serialized. * serialized before insertion. Strings will be stored as plain text and not
* @param $use_language * serialized.
* @param bool $use_language
* If TRUE, the data will be cached specific to the currently active language. * If TRUE, the data will be cached specific to the currently active language.
*/ */
function views_cache_set($cid, $data, $use_language = FALSE) { function views_cache_set($cid, $data, $use_language = FALSE) {
@ -198,7 +202,8 @@ function views_cache_set($cid, $data, $use_language = FALSE) {
* @param int $cid * @param int $cid
* The cache ID of the data to retrieve. * The cache ID of the data to retrieve.
* @param bool $use_language * @param bool $use_language
* If TRUE, the data will be requested specific to the currently active language. * If TRUE, the data will be requested specific to the currently active
* language.
* *
* @return stdClass|bool * @return stdClass|bool
* The cache or FALSE on failure. * The cache or FALSE on failure.

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
* Built in plugins for Views output handling. * Built in plugins for Views output handling.
*/ */
// @todo: Remove this once update.php can use the registry // @todo Remove this once update.php can use the registry.
views_include('base'); views_include('base');
/** /**
@ -101,7 +101,7 @@ function views_views_plugins() {
'title' => t('Empty display extender'), 'title' => t('Empty display extender'),
'help' => t('Default settings for this view.'), 'help' => t('Default settings for this view.'),
'handler' => 'views_plugin_display_extender', 'handler' => 'views_plugin_display_extender',
// You can force the plugin to be enabled // You can force the plugin to be enabled.
'enabled' => FALSE, 'enabled' => FALSE,
'no ui' => TRUE, 'no ui' => TRUE,
), ),
@ -160,7 +160,8 @@ function views_views_plugins() {
'help' => t('Displays the default summary as a list.'), 'help' => t('Displays the default summary as a list.'),
'handler' => 'views_plugin_style_summary', 'handler' => 'views_plugin_style_summary',
'theme' => 'views_view_summary', 'theme' => 'views_view_summary',
'type' => 'summary', // only shows up as a summary style 'type' => 'summary',
// only shows up as a summary style.
'uses options' => TRUE, 'uses options' => TRUE,
'help topic' => 'style-summary', 'help topic' => 'style-summary',
), ),
@ -169,7 +170,8 @@ function views_views_plugins() {
'help' => t('Displays the summary unformatted, with option for one after another or inline.'), 'help' => t('Displays the summary unformatted, with option for one after another or inline.'),
'handler' => 'views_plugin_style_summary_unformatted', 'handler' => 'views_plugin_style_summary_unformatted',
'theme' => 'views_view_summary_unformatted', 'theme' => 'views_view_summary_unformatted',
'type' => 'summary', // only shows up as a summary style 'type' => 'summary',
// only shows up as a summary style.
'uses options' => TRUE, 'uses options' => TRUE,
'help topic' => 'style-summary-unformatted', 'help topic' => 'style-summary-unformatted',
), ),
@ -266,7 +268,7 @@ function views_views_plugins() {
'views_query' => array( 'views_query' => array(
'title' => t('SQL Query'), 'title' => t('SQL Query'),
'help' => t('Query will be generated and run using the Drupal database API.'), 'help' => t('Query will be generated and run using the Drupal database API.'),
'handler' => 'views_plugin_query_default' 'handler' => 'views_plugin_query_default',
), ),
), ),
'cache' => array( 'cache' => array(
@ -356,7 +358,7 @@ function views_views_plugins() {
'handler' => 'views_plugin_localization', 'handler' => 'views_plugin_localization',
'parent' => '', 'parent' => '',
), ),
'none' => array( 'none' => array(
'title' => t('None'), 'title' => t('None'),
'help' => t('Do not pass admin strings for translation.'), 'help' => t('Do not pass admin strings for translation.'),
'handler' => 'views_plugin_localization_none', 'handler' => 'views_plugin_localization_none',
@ -381,7 +383,8 @@ function views_views_plugins() {
'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.'), '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', 'handler' => 'views_plugin_style_summary_jump_menu',
'theme' => 'views_view_summary_jump_menu', 'theme' => 'views_view_summary_jump_menu',
'type' => 'summary', // only shows up as a summary style 'type' => 'summary',
// only shows up as a summary style.
'uses options' => TRUE, 'uses options' => TRUE,
'help topic' => 'style-summary-jump-menu', 'help topic' => 'style-summary-jump-menu',
); );
@ -417,7 +420,7 @@ function views_discover_plugins() {
} }
$module_dir = isset($result['module']) ? $result['module'] : $module; $module_dir = isset($result['module']) ? $result['module'] : $module;
// Setup automatic path/file finding for theme registration // Setup automatic path/file finding for theme registration.
if ($module_dir == 'views') { if ($module_dir == 'views') {
$theme_path = drupal_get_path('module', $module_dir) . '/theme'; $theme_path = drupal_get_path('module', $module_dir) . '/theme';
$theme_file = 'theme.inc'; $theme_file = 'theme.inc';
@ -452,7 +455,7 @@ function views_discover_plugins() {
// Set the internal name to be able to read it out later. // Set the internal name to be able to read it out later.
$def['name'] = $plugin; $def['name'] = $plugin;
// merge the new data in // merge the new data in.
$cache[$type][$plugin] = $def; $cache[$type][$plugin] = $def;
} }
} }
@ -467,29 +470,30 @@ function views_discover_plugins() {
* Abstract base class to provide interface common to all plugins. * Abstract base class to provide interface common to all plugins.
*/ */
class views_plugin extends views_object { class views_plugin extends views_object {
/** /**
* The top object of a view. * The top object of a view.
* *
* @var view * @var view
*/ */
var $view = NULL; public $view = NULL;
/** /**
* The current used views display. * The current used views display.
* *
* @var views_display * @var views_display
*/ */
var $display = NULL; public $display = NULL;
/** /**
* The plugin type of this plugin, for example style or query. * The plugin type of this plugin, for example style or query.
*/ */
var $plugin_type = NULL; public $plugin_type = NULL;
/** /**
* The plugin name of this plugin, for example table or full. * The plugin name of this plugin, for example table or full.
*/ */
var $plugin_name = NULL; public $plugin_name = NULL;
/** /**
* Init will be called after construct, when the plugin is attached to a * Init will be called after construct, when the plugin is attached to a
@ -499,7 +503,7 @@ class views_plugin extends views_object {
/** /**
* Provide a form to edit options for this plugin. * Provide a form to edit options for this plugin.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
// Some form elements belong in a fieldset for presentation, but can't // Some form elements belong in a fieldset for presentation, but can't
// be moved into one because of the form_state['values'] hierarchy. Those // be moved into one because of the form_state['values'] hierarchy. Those
// elements can add a #fieldset => 'fieldset_name' property, and they'll // elements can add a #fieldset => 'fieldset_name' property, and they'll
@ -510,22 +514,25 @@ class views_plugin extends views_object {
/** /**
* Validate the options form. * Validate the options form.
*/ */
function options_validate(&$form, &$form_state) { } public function options_validate(&$form, &$form_state) {
}
/** /**
* Handle any special handling on the validate form. * Handle any special handling on the validate form.
*/ */
function options_submit(&$form, &$form_state) { } public function options_submit(&$form, &$form_state) {
}
/** /**
* Add anything to the query that we might need to. * Add anything to the query that we might need to.
*/ */
function query() { } public function query() {
}
/** /**
* Provide a full list of possible theme templates used by this style. * Provide a full list of possible theme templates used by this style.
*/ */
function theme_functions() { public function theme_functions() {
if (empty($this->definition['theme'])) { if (empty($this->definition['theme'])) {
$this->definition['theme'] = 'views_view'; $this->definition['theme'] = 'views_view';
} }
@ -533,9 +540,9 @@ class views_plugin extends views_object {
} }
/** /**
* Provide a list of additional theme functions for the theme information page * Provide a list of additional theme functions for the theme info page.
*/ */
function additional_theme_functions() { public function additional_theme_functions() {
$funcs = array(); $funcs = array();
if (!empty($this->definition['additional themes'])) { if (!empty($this->definition['additional themes'])) {
foreach ($this->definition['additional themes'] as $theme => $type) { foreach ($this->definition['additional themes'] as $theme => $type) {
@ -548,16 +555,18 @@ class views_plugin extends views_object {
/** /**
* Validate that the plugin is correct and can be saved. * Validate that the plugin is correct and can be saved.
* *
* @return * @return array
* An array of error strings to tell the user what is wrong with this * An array of error strings to tell the user what is wrong with this
* plugin. * plugin.
*/ */
function validate() { return array(); } public function validate() {
return array();
}
/** /**
* Returns the summary of the settings in the display. * Returns the summary of the settings in the display.
*/ */
function summary_title() { public function summary_title() {
return t('Settings'); return t('Settings');
} }
/** /**
@ -565,12 +574,13 @@ class views_plugin extends views_object {
* *
* This appears on the ui beside each plugin and beside the settings link. * This appears on the ui beside each plugin and beside the settings link.
*/ */
function plugin_title() { public function plugin_title() {
if (isset($this->definition['short title'])) { if (isset($this->definition['short title'])) {
return check_plain($this->definition['short title']); return check_plain($this->definition['short title']);
} }
return check_plain($this->definition['title']); return check_plain($this->definition['title']);
} }
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,13 @@
}); });
$('form', ajax_body).once('views-ajax-submit-processed').each(function() { $('form', ajax_body).once('views-ajax-submit-processed').each(function() {
var element_settings = { 'url': response.url, 'event': 'submit', 'progress': { 'type': 'throbber' } }; var element_settings = {
'url': response.url,
'event': 'submit',
'progress': {
'type': 'throbber'
}
};
var $form = $(this); var $form = $(this);
var id = $form.attr('id'); var id = $form.attr('id');
Drupal.ajax[id] = new Drupal.ajax(id, this, element_settings); Drupal.ajax[id] = new Drupal.ajax(id, this, element_settings);
@ -90,7 +96,7 @@
}; };
/** /**
* Get rid of irritating tabledrag messages * Get rid of irritating tabledrag messages.
*/ */
Drupal.theme.tableDragChangedWarning = function () { Drupal.theme.tableDragChangedWarning = function () {
return []; return [];
@ -143,7 +149,9 @@
var base_element_settings = { var base_element_settings = {
'event': 'click', 'event': 'click',
'progress': { 'type': 'throbber' } 'progress': {
'type': 'throbber'
}
}; };
// Bind AJAX behaviors to all items showing the class. // Bind AJAX behaviors to all items showing the class.
$('a.views-ajax-link', context).once('views-ajax-processed').each(function () { $('a.views-ajax-link', context).once('views-ajax-processed').each(function () {
@ -158,23 +166,23 @@
$('div#views-live-preview a') $('div#views-live-preview a')
.once('views-ajax-processed').each(function () { .once('views-ajax-processed').each(function () {
// We don't bind to links without a URL. // We don't bind to links without a URL.
if (!$(this).attr('href')) { if (!$(this).attr('href')) {
return true; return true;
} }
var element_settings = base_element_settings; var element_settings = base_element_settings;
// Set the URL to go to the anchor. // Set the URL to go to the anchor.
element_settings.url = $(this).attr('href'); element_settings.url = $(this).attr('href');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') { if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') {
return true; return true;
} }
element_settings.wrapper = 'views-live-preview'; element_settings.wrapper = 'views-live-preview';
element_settings.method = 'html'; element_settings.method = 'html';
var base = $(this).attr('id'); var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
}); });
// Within a live preview, make exposed widget form buttons re-trigger the // Within a live preview, make exposed widget form buttons re-trigger the
// Preview button. // Preview button.
@ -182,29 +190,29 @@
// of the main Edit form. // of the main Edit form.
$('div#views-live-preview input[type=submit]') $('div#views-live-preview input[type=submit]')
.once('views-ajax-processed').each(function(event) { .once('views-ajax-processed').each(function(event) {
$(this).click(function () { $(this).click(function () {
this.form.clk = this; this.form.clk = this;
return true; return true;
});
var element_settings = base_element_settings;
// Set the URL to go to the anchor.
element_settings.url = $(this.form).attr('action');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-live-preview';
element_settings.method = 'html';
element_settings.event = 'click';
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
}); });
var element_settings = base_element_settings;
// Set the URL to go to the anchor.
element_settings.url = $(this.form).attr('action');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) != 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-live-preview';
element_settings.method = 'html';
element_settings.event = 'click';
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
if (!this.collapseReplaced && Drupal.collapseScrollIntoView) { if (!this.collapseReplaced && Drupal.collapseScrollIntoView) {
this.collapseReplaced = true; this.collapseReplaced = true;
Drupal.collapseScrollIntoView = function (node) { Drupal.collapseScrollIntoView = function (node) {
for (var $parent = $(node); $parent.get(0) != document && $parent.size() != 0; $parent = $parent.parent()) { for (var $parent = $(node); $parent.get(0) != document && $parent.length != 0; $parent = $parent.parent()) {
if ($parent.css('overflow') == 'scroll' || $parent.css('overflow') == 'auto') { if ($parent.css('overflow') == 'scroll' || $parent.css('overflow') == 'auto') {
if (Drupal.viewsUi.resizeModal) { if (Drupal.viewsUi.resizeModal) {
// If the modal is already at the max height, don't bother with // If the modal is already at the max height, don't bother with

View File

@ -4,148 +4,159 @@
*/ */
(function ($) { (function ($) {
/** /**
* Attaches the AJAX behavior to Views exposed filter forms and key View links. * Attaches the AJAX behavior to exposed filter forms and key views links.
*/ */
Drupal.behaviors.ViewsAjaxView = {}; Drupal.behaviors.ViewsAjaxView = {};
Drupal.behaviors.ViewsAjaxView.attach = function() { Drupal.behaviors.ViewsAjaxView.attach = function() {
if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) { if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
$.each(Drupal.settings.views.ajaxViews, function(i, settings) { $.each(Drupal.settings.views.ajaxViews, function(i, settings) {
Drupal.views.instances[i] = new Drupal.views.ajaxView(settings); Drupal.views.instances[i] = new Drupal.views.ajaxView(settings);
}); });
}
};
Drupal.views = {};
Drupal.views.instances = {};
/**
* Javascript object for a certain view.
*/
Drupal.views.ajaxView = function(settings) {
var selector = '.view-dom-id-' + settings.view_dom_id;
this.$view = $(selector);
// Retrieve the path to use for views' ajax.
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];
}
// Check if there are any GET parameters to send to views.
var queryString = window.location.search || '';
if (queryString !== '') {
// Remove the question mark and Drupal path component if any.
var queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
if (queryString !== '') {
// If there is a '?' in ajax_path, clean url are on and & should be used to add parameters.
queryString = ((/\?/.test(ajax_path)) ? '&' : '?') + queryString;
} }
}
this.element_settings = {
url: ajax_path + queryString,
submit: settings,
setClick: true,
event: 'click',
selector: selector,
progress: { type: 'throbber' }
}; };
this.settings = settings; Drupal.views = {};
Drupal.views.instances = {};
// Add the ajax to exposed forms. /**
this.$exposed_form = $('#views-exposed-form-'+ settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-')); * Javascript object for a certain view.
this.$exposed_form.once(jQuery.proxy(this.attachExposedFormAjax, this)); */
Drupal.views.ajaxView = function(settings) {
var selector = '.view-dom-id-' + settings.view_dom_id;
this.$view = $(selector);
// Store Drupal.ajax objects here for all pager links. // Retrieve the path to use for views' ajax.
this.links = []; var ajax_path = Drupal.settings.views.ajax_path;
// Add the ajax to pagers. // If there are multiple views this might've ended up showing up multiple
this.$view // times.
if (ajax_path.constructor.toString().indexOf("Array") != -1) {
ajax_path = ajax_path[0];
}
// Check if there are any GET parameters to send to views.
var queryString = window.location.search || '';
if (queryString !== '') {
// Remove the question mark and Drupal path component if any.
var queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
if (queryString !== '') {
// If there is a '?' in ajax_path, clean url are on and & should be
// used to add parameters.
queryString = ((/\?/.test(ajax_path)) ? '&' : '?') + queryString;
}
}
this.element_settings = {
url: ajax_path + queryString,
submit: settings,
setClick: true,
event: 'click',
selector: selector,
progress: {
type: 'throbber'
}
};
this.settings = settings;
// Add the ajax to exposed forms.
this.$exposed_form = $('#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
this.$exposed_form.once(jQuery.proxy(this.attachExposedFormAjax, this));
// Store Drupal.ajax objects here for all pager links.
this.links = [];
// Add the ajax to pagers.
this.$view
// Don't attach to nested views. Doing so would attach multiple behaviors // Don't attach to nested views. Doing so would attach multiple behaviors
// to a given element. // to a given element.
.filter(jQuery.proxy(this.filterNestedViews, this)) .filter(jQuery.proxy(this.filterNestedViews, this))
.once(jQuery.proxy(this.attachPagerAjax, this)); .once(jQuery.proxy(this.attachPagerAjax, this));
// Add a trigger to update this view specifically. In order to trigger a // Add a trigger to update this view specifically. In order to trigger a
// refresh use the following code. // refresh use the following code.
// //
// @code // @code
// jQuery('.view-name').trigger('RefreshView'); // jQuery('.view-name').trigger('RefreshView');
// @endcode // @endcode
// Add a trigger to update this view specifically. // Add a trigger to update this view specifically.
var self_settings = this.element_settings; var self_settings = this.element_settings;
self_settings.event = 'RefreshView'; self_settings.event = 'RefreshView';
this.refreshViewAjax = new Drupal.ajax(this.selector, this.$view, self_settings); this.refreshViewAjax = new Drupal.ajax(this.selector, this.$view, self_settings);
}; };
Drupal.views.ajaxView.prototype.attachExposedFormAjax = function() { Drupal.views.ajaxView.prototype.attachExposedFormAjax = function() {
var button = $('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form); var button = $('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form);
button = button[0]; button = button[0];
this.exposedFormAjax = new Drupal.ajax($(button).attr('id'), button, this.element_settings); // Call the autocomplete submit before doing AJAX.
}; $(button).click(function () {
if (Drupal.autocompleteSubmit) {
Drupal.autocompleteSubmit();
}
});
Drupal.views.ajaxView.prototype.filterNestedViews= function() { this.exposedFormAjax = new Drupal.ajax($(button).attr('id'), button, this.element_settings);
// If there is at least one parent with a view class, this view };
// is nested (e.g., an attachment). Bail.
return !this.$view.parents('.view').size();
};
/** Drupal.views.ajaxView.prototype.filterNestedViews = function() {
* Attach the ajax behavior to each link. // If there is at least one parent with a view class, this view
*/ // is nested (e.g., an attachment). Bail.
Drupal.views.ajaxView.prototype.attachPagerAjax = function() { return !this.$view.parents('.view').length;
this.$view.find('ul.pager > li > a, th.views-field a, .attachment .views-summary a') };
.each(jQuery.proxy(this.attachPagerLinkAjax, this));
};
/** /**
* Attach the ajax behavior to a singe link. * Attach the ajax behavior to each link.
*/ */
Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function(id, link) { Drupal.views.ajaxView.prototype.attachPagerAjax = function() {
var $link = $(link); this.$view.find('ul.pager > li > a, th.views-field a, .attachment .views-summary a')
var viewData = {}; .each(jQuery.proxy(this.attachPagerLinkAjax, this));
var href = $link.attr('href'); };
// Construct an object using the settings defaults and then overriding
// with data specific to the link. /**
$.extend( * Attach the ajax behavior to a singe link.
*/
Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function(id, link) {
var $link = $(link);
var viewData = {};
var href = $link.attr('href');
// Construct an object using the settings defaults and then overriding
// with data specific to the link.
$.extend(
viewData, viewData,
this.settings, this.settings,
Drupal.Views.parseQueryString(href), Drupal.Views.parseQueryString(href),
// Extract argument data from the URL. // Extract argument data from the URL.
Drupal.Views.parseViewArgs(href, this.settings.view_base_path) Drupal.Views.parseViewArgs(href, this.settings.view_base_path)
); );
// For anchor tags, these will go to the target of the anchor rather // For anchor tags, these will go to the target of the anchor rather
// than the usual location. // than the usual location.
$.extend(viewData, Drupal.Views.parseViewArgs(href, this.settings.view_base_path)); $.extend(viewData, Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
this.element_settings.submit = viewData; this.element_settings.submit = viewData;
this.pagerAjax = new Drupal.ajax(false, $link, this.element_settings); this.pagerAjax = new Drupal.ajax(false, $link, this.element_settings);
this.links.push(this.pagerAjax); this.links.push(this.pagerAjax);
}; };
Drupal.ajax.prototype.commands.viewsScrollTop = function (ajax, response, status) { Drupal.ajax.prototype.commands.viewsScrollTop = function (ajax, response, status) {
// Scroll to the top of the view. This will allow users // Scroll to the top of the view. This will allow users
// to browse newly loaded content after e.g. clicking a pager // to browse newly loaded content after e.g. clicking a pager
// link. // link.
var offset = $(response.selector).offset(); var offset = $(response.selector).offset();
// We can't guarantee that the scrollable object should be // We can't guarantee that the scrollable object should be
// the body, as the view could be embedded in something // the body, as the view could be embedded in something
// more complex such as a modal popup. Recurse up the DOM // more complex such as a modal popup. Recurse up the DOM
// and scroll the first element that has a non-zero top. // and scroll the first element that has a non-zero top.
var scrollTarget = response.selector; var scrollTarget = response.selector;
while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) { while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) {
scrollTarget = $(scrollTarget).parent(); scrollTarget = $(scrollTarget).parent();
} }
// Only scroll upward // Only scroll upward.
if (offset.top - 10 < $(scrollTarget).scrollTop()) { if (offset.top - 10 < $(scrollTarget).scrollTop()) {
$(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500); $(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500);
} }
}; };
})(jQuery); })(jQuery);

View File

@ -4,112 +4,112 @@
*/ */
(function ($) { (function ($) {
Drupal.Views = {}; Drupal.Views = {};
/**
* jQuery UI tabs, Views integration component
*/
Drupal.behaviors.viewsTabs = {
attach: function (context) {
if ($.viewsUi && $.viewsUi.tabs) {
$('#views-tabset').once('views-processed').viewsTabs({
selectedClass: 'active'
});
}
$('a.views-remove-link').once('views-processed').click(function(event) {
var id = $(this).attr('id').replace('views-remove-link-', '');
$('#views-row-' + id).hide();
$('#views-removed-' + id).attr('checked', true);
event.preventDefault();
});
/** /**
* Here is to handle display deletion * JQuery UI tabs, Views integration component.
* (checking in the hidden checkbox and hiding out the row) */
*/ Drupal.behaviors.viewsTabs = {
$('a.display-remove-link') attach: function (context) {
.addClass('display-processed') if ($.viewsUi && $.viewsUi.tabs) {
.click(function() { $('#views-tabset').once('views-processed').viewsTabs({
var id = $(this).attr('id').replace('display-remove-link-', ''); selectedClass: 'active'
$('#display-row-' + id).hide(); });
$('#display-removed-' + id).attr('checked', true); }
return false;
});
}
};
/** $('a.views-remove-link').once('views-processed').click(function(event) {
var id = $(this).attr('id').replace('views-remove-link-', '');
$('#views-row-' + id).hide();
$('#views-removed-' + id).attr('checked', true);
event.preventDefault();
});
/**
* Here is to handle display deletion
* (checking in the hidden checkbox and hiding out the row).
*/
$('a.display-remove-link')
.addClass('display-processed')
.click(function() {
var id = $(this).attr('id').replace('display-remove-link-', '');
$('#display-row-' + id).hide();
$('#display-removed-' + id).attr('checked', true);
return false;
});
}
};
/**
* Helper function to parse a querystring. * Helper function to parse a querystring.
*/ */
Drupal.Views.parseQueryString = function (query) { Drupal.Views.parseQueryString = function (query) {
var args = {}; var args = {};
var pos = query.indexOf('?'); var pos = query.indexOf('?');
if (pos != -1) { if (pos != -1) {
query = query.substring(pos + 1); query = query.substring(pos + 1);
} }
var pairs = query.split('&'); var pairs = query.split('&');
for(var i in pairs) { for (var i in pairs) {
if (typeof(pairs[i]) == 'string') { if (typeof(pairs[i]) == 'string') {
var pair = pairs[i].split('='); var pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present. // Ignore the 'q' path argument, if present.
if (pair[0] != 'q' && pair[1]) { if (pair[0] != 'q' && pair[1]) {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
} }
} }
} return args;
return args; };
};
/** /**
* Helper function to return a view's arguments based on a path. * Helper function to return a view's arguments based on a path.
*/ */
Drupal.Views.parseViewArgs = function (href, viewPath) { Drupal.Views.parseViewArgs = function (href, viewPath) {
// Provide language prefix. // Provide language prefix.
if (Drupal.settings.pathPrefix) { if (Drupal.settings.pathPrefix) {
var viewPath = Drupal.settings.pathPrefix + viewPath; var viewPath = Drupal.settings.pathPrefix + viewPath;
} }
var returnObj = {}; var returnObj = {};
var path = Drupal.Views.getPath(href); var path = Drupal.Views.getPath(href);
// Ensure we have a correct path. // Ensure we have a correct path.
if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') { if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') {
var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length)); var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
returnObj.view_args = args; returnObj.view_args = args;
returnObj.view_path = path; returnObj.view_path = path;
} }
return returnObj; return returnObj;
}; };
/** /**
* Strip off the protocol plus domain from an href. * Strip off the protocol plus domain from an href.
*/ */
Drupal.Views.pathPortion = function (href) { Drupal.Views.pathPortion = function (href) {
// Remove e.g. http://example.com if present. // Remove e.g. http://example.com if present.
var protocol = window.location.protocol; var protocol = window.location.protocol;
if (href.substring(0, protocol.length) == protocol) { if (href.substring(0, protocol.length) == protocol) {
// 2 is the length of the '//' that normally follows the protocol // 2 is the length of the '//' that normally follows the protocol.
href = href.substring(href.indexOf('/', protocol.length + 2)); href = href.substring(href.indexOf('/', protocol.length + 2));
} }
return href; return href;
}; };
/** /**
* Return the Drupal path portion of an href. * Return the Drupal path portion of an href.
*/ */
Drupal.Views.getPath = function (href) { Drupal.Views.getPath = function (href) {
href = Drupal.Views.pathPortion(href); href = Drupal.Views.pathPortion(href);
href = href.substring(Drupal.settings.basePath.length, href.length); href = href.substring(Drupal.settings.basePath.length, href.length);
// 3 is the length of the '?q=' added to the url without clean urls. // 3 is the length of the '?q=' added to the url without clean urls.
if (href.substring(0, 3) == '?q=') { if (href.substring(0, 3) == '?q=') {
href = href.substring(3, href.length); href = href.substring(3, href.length);
}
var chars = ['#', '?', '&'];
for (var i in chars) {
if (href.indexOf(chars[i]) > -1) {
href = href.substr(0, href.indexOf(chars[i]));
} }
} var chars = ['#', '?', '&'];
return href; for (var i in chars) {
}; if (href.indexOf(chars[i]) > -1) {
href = href.substr(0, href.indexOf(chars[i]));
}
}
return href;
};
})(jQuery); })(jQuery);

View File

@ -1,4 +1,5 @@
/** /**
* @file
* This is part of a patch to address a jQueryUI bug. The bug is responsible * This is part of a patch to address a jQueryUI bug. The bug is responsible
* for the inability to scroll a page when a modal dialog is active. If the content * for the inability to scroll a page when a modal dialog is active. If the content
* of the dialog extends beyond the bottom of the viewport, the user is only able * of the dialog extends beyond the bottom of the viewport, the user is only able
@ -15,13 +16,16 @@
* *
* The original code for this object: * The original code for this object:
* $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','), * $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
* function(event) { return event + '.dialog-overlay'; }).join(' '), * function(event) {
* * return event + '.dialog-overlay';
* }).join(' '),
*/ */
(function ($, undefined) { (function ($, undefined) {
if ($.ui && $.ui.dialog && $.ui.dialog.overlay) { if ($.ui && $.ui.dialog && $.ui.dialog.overlay) {
$.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','), $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','),
function(event) { return event + '.dialog-overlay'; }).join(' '); function(event) {
return event + '.dialog-overlay';
}).join(' ');
} }
}(jQuery)); }(jQuery));

View File

@ -187,7 +187,8 @@ Drupal.viewsUi.addItemForm.prototype.handleCheck = function (event) {
else { else {
var length = this.checkedItems.length; var length = this.checkedItems.length;
var position = jQuery.inArray(label, this.checkedItems); var position = jQuery.inArray(label, this.checkedItems);
// Delete the item from the list and take sure that the list doesn't have undefined items left. // Delete the item from the list and take sure that the list doesn't have
// undefined items left.
for (var i = 0; i < this.checkedItems.length; i++) { for (var i = 0; i < this.checkedItems.length; i++) {
if (i == position) { if (i == position) {
this.checkedItems.splice(i, 1); this.checkedItems.splice(i, 1);
@ -245,7 +246,7 @@ Drupal.behaviors.viewsUiRenderAddViewButton.attach = function (context, settings
}); });
$addDisplayDropdown.appendTo($menu); $addDisplayDropdown.appendTo($menu);
// Add the click handler for the add display button // Add the click handler for the add display button.
$('li.add > a', $menu).bind('click', function (event) { $('li.add > a', $menu).bind('click', function (event) {
event.preventDefault(); event.preventDefault();
var $trigger = $(this); var $trigger = $(this);
@ -668,7 +669,7 @@ Drupal.viewsUi.rearrangeFilterHandler.prototype.modifyTableDrag = function () {
// Make sure the "group" dropdown is properly updated when rows are dragged // Make sure the "group" dropdown is properly updated when rows are dragged
// into an empty filter group. This is borrowed heavily from the block.js // into an empty filter group. This is borrowed heavily from the block.js
// implementation of tableDrag.onDrop(). // Implements tableDrag.onDrop().
var groupRow = $(this.rowObject.element).prevAll('tr.group-message').get(0); var groupRow = $(this.rowObject.element).prevAll('tr.group-message').get(0);
var groupName = groupRow.className.replace(/([^ ]+[ ]+)*group-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); var groupName = groupRow.className.replace(/([^ ]+[ ]+)*group-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
var groupField = $('select.views-group-select', this.rowObject.element); var groupField = $('select.views-group-select', this.rowObject.element);
@ -769,14 +770,14 @@ Drupal.behaviors.viewsFilterConfigSelectAll.attach = function(context) {
$('#views-ui-config-item-form div.form-item-options-value-all', context).once(function() { $('#views-ui-config-item-form div.form-item-options-value-all', context).once(function() {
$(this).show(); $(this).show();
}) })
.find('input[type=checkbox]') .find('input[type=checkbox]')
.click(function() { .click(function() {
var checked = $(this).is(':checked'); var checked = $(this).is(':checked');
// Update all checkbox beside the select all checkbox. // Update all checkbox beside the select all checkbox.
$(this).parents('.form-checkboxes').find('input[type=checkbox]').each(function() { $(this).parents('.form-checkboxes').find('input[type=checkbox]').each(function() {
$(this).attr('checked', checked); $(this).attr('checked', checked);
});
}); });
});
// Uncheck the select all checkbox if any of the others are unchecked. // Uncheck the select all checkbox if any of the others are unchecked.
$('#views-ui-config-item-form div.form-type-checkbox').not($('.form-item-options-value-all')).find('input[type=checkbox]').each(function() { $('#views-ui-config-item-form div.form-type-checkbox').not($('.form-item-options-value-all')).find('input[type=checkbox]').each(function() {
$(this).click(function() { $(this).click(function() {
@ -926,7 +927,7 @@ Drupal.behaviors.viewsUiOverrideSelect.attach = function (context, settings) {
$submit.val(Drupal.t('Apply (this display)')); $submit.val(Drupal.t('Apply (this display)'));
} }
}) })
.trigger('change'); .trigger('change');
}); });
}; };
@ -935,13 +936,14 @@ Drupal.viewsUi.resizeModal = function (e, no_shrink) {
var $ = jQuery; var $ = jQuery;
var $modal = $('.views-ui-dialog'); var $modal = $('.views-ui-dialog');
var $scroll = $('.scroll', $modal); var $scroll = $('.scroll', $modal);
if ($modal.size() == 0 || $modal.css('display') == 'none') { if ($modal.length == 0 || $modal.css('display') == 'none') {
return; return;
} }
var maxWidth = parseInt($(window).width() * .85); // 70% of window var maxWidth = parseInt($(window).width() * .85);
var minWidth = parseInt($(window).width() * .6); // 70% of window // 70% of window.
var minWidth = parseInt($(window).width() * .6);
// 70% of window.
// Set the modal to the minwidth so that our width calculation of // Set the modal to the minwidth so that our width calculation of
// children works. // children works.
$modal.css('width', minWidth); $modal.css('width', minWidth);
@ -976,7 +978,6 @@ Drupal.viewsUi.resizeModal = function (e, no_shrink) {
// Now, calculate what the difference between the scroll and the modal // Now, calculate what the difference between the scroll and the modal
// will be. // will be.
var difference = 0; var difference = 0;
difference += parseInt($scroll.css('padding-top')); difference += parseInt($scroll.css('padding-top'));
difference += parseInt($scroll.css('padding-bottom')); difference += parseInt($scroll.css('padding-bottom'));
@ -1001,7 +1002,7 @@ Drupal.viewsUi.resizeModal = function (e, no_shrink) {
width = maxWidth; width = maxWidth;
} }
// Get where we should move content to // Get where we should move content to.
var top = ($(window).height() / 2) - (height / 2); var top = ($(window).height() / 2) - (height / 2);
var left = ($(window).width() / 2) - (width / 2); var left = ($(window).width() / 2) - (width / 2);

View File

@ -4,13 +4,13 @@
*/ */
(function ($) { (function ($) {
Drupal.behaviors.viewsContextualLinks = { Drupal.behaviors.viewsContextualLinks = {
attach: function (context) { attach: function (context) {
// If there are views-related contextual links attached to the main page // If there are views-related contextual links attached to the main page
// content, find the smallest region that encloses both the links and the // content, find the smallest region that encloses both the links and the
// view, and display it as a contextual links region. // view, and display it as a contextual links region.
$('.views-contextual-links-page', context).closest(':has(".view"):not("body")').addClass('contextual-links-region'); $('.views-contextual-links-page', context).closest(':has(".view"):not("body")').addClass('contextual-links-region');
} }
}; };
})(jQuery); })(jQuery);

View File

@ -4,18 +4,18 @@
*/ */
(function ($) { (function ($) {
Drupal.behaviors.viewsUIList = { Drupal.behaviors.viewsUIList = {
attach: function (context) { attach: function (context) {
$('#ctools-export-ui-list-items thead a').once('views-ajax-processed').each(function() { $('#ctools-export-ui-list-items thead a').once('views-ajax-processed').each(function() {
$(this).click(function() { $(this).click(function() {
var query = $.deparam.querystring(this.href); var query = $.deparam.querystring(this.href);
$('#ctools-export-ui-list-form select[name=order]').val(query['order']); $('#ctools-export-ui-list-form select[name=order]').val(query['order']);
$('#ctools-export-ui-list-form select[name=sort]').val(query['sort']); $('#ctools-export-ui-list-form select[name=sort]').val(query['sort']);
$('#ctools-export-ui-list-form input.ctools-auto-submit-click').trigger('click'); $('#ctools-export-ui-list-form input.ctools-auto-submit-click').trigger('click');
return false; return false;
});
}); });
}); }
} };
};
})(jQuery); })(jQuery);

View File

@ -12,13 +12,12 @@
*/ */
function aggregator_views_data() { function aggregator_views_data() {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Main Aggregator Item base table // Main Aggregator Item base table.
// Define the base group of this table. Fields that don't have a group
// Define the base group of this table. Fields that don't // defined will go into this field by default.
// have a group defined will go into this field by default.
$data['aggregator_item']['table']['group'] = t('Aggregator'); $data['aggregator_item']['table']['group'] = t('Aggregator');
// Advertise this table as a possible base table // Advertise this table as a possible base table.
$data['aggregator_item']['table']['base'] = array( $data['aggregator_item']['table']['base'] = array(
'field' => 'iid', 'field' => 'iid',
'title' => t('Aggregator item'), 'title' => t('Aggregator item'),
@ -27,43 +26,25 @@ function aggregator_views_data() {
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// Fields // Fields
// Item ID / 'iid'.
// 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( $data['aggregator_item']['iid'] = array(
// The item it appears as on the UI,
'title' => t('Item ID'), 'title' => t('Item ID'),
'help' => t('The unique ID of the aggregator item.'), // The help that appears on the UI, // The help that appears on the UI,
// Information for displaying the iid 'help' => t('The unique ID of the aggregator item.'),
// Information for displaying the iid.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_numeric', 'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
// Information for accepting a iid as an argument // Information for accepting a iid as an argument.
'argument' => array( 'argument' => array(
'handler' => 'views_handler_argument_aggregator_iid', 'handler' => 'views_handler_argument_aggregator_iid',
'name field' => 'title', // the field to display in the summary. 'name field' => 'title',
// The field to display in the summary.
'numeric' => TRUE, 'numeric' => TRUE,
), ),
// Information for accepting a nid as a filter // Information for accepting a nid as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_numeric', 'handler' => 'views_handler_filter_numeric',
), ),
@ -73,55 +54,58 @@ function aggregator_views_data() {
), ),
); );
// title // Title.
$data['aggregator_item']['title'] = array( $data['aggregator_item']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Title'),
'help' => t('The title of the aggregator item.'), 'help' => t('The title of the aggregator item.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_aggregator_title_link', 'handler' => 'views_handler_field_aggregator_title_link',
'extra' => array('link'), 'extra' => array('link'),
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
); );
// link // Link.
$data['aggregator_item']['link'] = array( $data['aggregator_item']['link'] = array(
'title' => t('Link'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Link'),
'help' => t('The link to the original source URL of the item.'), 'help' => t('The link to the original source URL of the item.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_url', 'handler' => 'views_handler_field_url',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
); );
// author // Author.
$data['aggregator_item']['author'] = array( $data['aggregator_item']['author'] = array(
'title' => t('Author'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Author'),
'help' => t('The author of the original imported item.'), 'help' => t('The author of the original imported item.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_aggregator_xss', 'handler' => 'views_handler_field_aggregator_xss',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
@ -130,19 +114,20 @@ function aggregator_views_data() {
), ),
); );
// guid // 'guid'.
$data['aggregator_item']['guid'] = array( $data['aggregator_item']['guid'] = array(
'title' => t('GUID'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('GUID'),
'help' => t('The guid of the original imported item.'), 'help' => t('The guid of the original imported item.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_xss', 'handler' => 'views_handler_field_xss',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
@ -151,34 +136,36 @@ function aggregator_views_data() {
), ),
); );
// feed body // Feed body.
$data['aggregator_item']['description'] = array( $data['aggregator_item']['description'] = array(
'title' => t('Body'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Body'),
'help' => t('The actual content of the imported item.'), 'help' => t('The actual content of the imported item.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_aggregator_xss', 'handler' => 'views_handler_field_aggregator_xss',
'click sortable' => FALSE, 'click sortable' => FALSE,
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
); );
// item timestamp // Item timestamp.
$data['aggregator_item']['timestamp'] = array( $data['aggregator_item']['timestamp'] = array(
'title' => t('Timestamp'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Timestamp'),
'help' => t('The date the original feed item was posted. (With some feeds, this will be the date it was imported.)'), '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 // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_date', 'handler' => 'views_handler_field_date',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort_date', 'handler' => 'views_handler_sort_date',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_date', 'handler' => 'views_handler_filter_date',
), ),
@ -187,10 +174,8 @@ function aggregator_views_data() {
), ),
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Aggregator feed table // Aggregator feed table.
$data['aggregator_feed']['table']['group'] = t('Aggregator feed'); $data['aggregator_feed']['table']['group'] = t('Aggregator feed');
// Explain how this table joins to others. // Explain how this table joins to others.
@ -201,22 +186,25 @@ function aggregator_views_data() {
), ),
); );
// fid // Feed ID / 'fid'.
$data['aggregator_feed']['fid'] = array( $data['aggregator_feed']['fid'] = array(
// The item it appears as on the UI,
'title' => t('Feed ID'), 'title' => t('Feed ID'),
'help' => t('The unique ID of the aggregator feed.'), // The help that appears on the UI, // The help that appears on the UI,
// Information for displaying the fid 'help' => t('The unique ID of the aggregator feed.'),
// Information for displaying the fid.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_numeric', 'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
// Information for accepting a fid as an argument // Information for accepting a fid as an argument.
'argument' => array( 'argument' => array(
'handler' => 'views_handler_argument_aggregator_fid', 'handler' => 'views_handler_argument_aggregator_fid',
'name field' => 'title', // the field to display in the summary. 'name field' => 'title',
// The field to display in the summary.
'numeric' => TRUE, 'numeric' => TRUE,
), ),
// Information for accepting a nid as a filter // Information for accepting a nid as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_numeric', 'handler' => 'views_handler_filter_numeric',
), ),
@ -226,20 +214,22 @@ function aggregator_views_data() {
), ),
); );
// title // Title.
$data['aggregator_feed']['title'] = array( $data['aggregator_feed']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Title'),
// The help that appears on the UI,
'help' => t('The title of the aggregator feed.'), 'help' => t('The title of the aggregator feed.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_aggregator_title_link', 'handler' => 'views_handler_field_aggregator_title_link',
'extra' => array('link'), 'extra' => array('link'),
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
@ -248,15 +238,16 @@ function aggregator_views_data() {
), ),
); );
// link // Link.
$data['aggregator_feed']['link'] = array( $data['aggregator_feed']['link'] = array(
'title' => t('Link'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Link'),
'help' => t('The link to the source URL of the feed.'), 'help' => t('The link to the source URL of the feed.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_url', 'handler' => 'views_handler_field_url',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
@ -265,15 +256,16 @@ function aggregator_views_data() {
), ),
); );
// feed last updated // Feed last updated.
$data['aggregator_feed']['checked'] = array( $data['aggregator_feed']['checked'] = array(
'title' => t('Last checked'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Last checked'),
'help' => t('The date the feed was last checked for new content.'), 'help' => t('The date the feed was last checked for new content.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_date', 'handler' => 'views_handler_field_date',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort_date', 'handler' => 'views_handler_sort_date',
), ),
@ -285,33 +277,35 @@ function aggregator_views_data() {
), ),
); );
// feed description // Feed description.
$data['aggregator_feed']['description'] = array( $data['aggregator_feed']['description'] = array(
'title' => t('Description'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Description'),
'help' => t('The description of the aggregator feed.'), 'help' => t('The description of the aggregator feed.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_xss', 'handler' => 'views_handler_field_xss',
'click sortable' => FALSE, 'click sortable' => FALSE,
), ),
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
); );
// feed last updated // Feed last updated.
$data['aggregator_feed']['modified'] = array( $data['aggregator_feed']['modified'] = array(
'title' => t('Last modified'), // The item it appears as on the UI, // The item it appears as on the UI,
'title' => t('Last modified'),
'help' => t('The date of the most recent new content on the feed.'), 'help' => t('The date of the most recent new content on the feed.'),
// Information for displaying a title as a field // Information for displaying a title as a field.
'field' => array( 'field' => array(
'handler' => 'views_handler_field_date', 'handler' => 'views_handler_field_date',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort_date', 'handler' => 'views_handler_sort_date',
), ),
// Information for accepting a title as a filter // Information for accepting a title as a filter.
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_date', 'handler' => 'views_handler_filter_date',
), ),
@ -321,8 +315,7 @@ function aggregator_views_data() {
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Aggregator category feed table // Aggregator category feed table.
$data['aggregator_category_feed']['table']['join'] = array( $data['aggregator_category_feed']['table']['join'] = array(
'aggregator_item' => array( 'aggregator_item' => array(
'left_field' => 'fid', 'left_field' => 'fid',
@ -331,8 +324,7 @@ function aggregator_views_data() {
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Aggregator category table // Aggregator category table.
$data['aggregator_category']['table']['group'] = t('Aggregator category'); $data['aggregator_category']['table']['group'] = t('Aggregator category');
$data['aggregator_category']['table']['join'] = array( $data['aggregator_category']['table']['join'] = array(
@ -343,7 +335,7 @@ function aggregator_views_data() {
), ),
); );
// cid // Category ID / 'cid'.
$data['aggregator_category']['cid'] = array( $data['aggregator_category']['cid'] = array(
'title' => t('Category ID'), 'title' => t('Category ID'),
'help' => t('The unique ID of the aggregator category.'), 'help' => t('The unique ID of the aggregator category.'),
@ -364,14 +356,14 @@ function aggregator_views_data() {
), ),
); );
// title // Title.
$data['aggregator_category']['title'] = array( $data['aggregator_category']['title'] = array(
'title' => t('Category'), 'title' => t('Category'),
'help' => t('The title of the aggregator category.'), 'help' => t('The title of the aggregator category.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field_aggregator_category', 'handler' => 'views_handler_field_aggregator_category',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'sort' => array( 'sort' => array(
'handler' => 'views_handler_sort', 'handler' => 'views_handler_sort',
), ),
@ -388,15 +380,18 @@ function aggregator_views_data() {
*/ */
function aggregator_views_plugins() { function aggregator_views_plugins() {
return array( return array(
'module' => 'views', // This just tells our themes are elsewhere. 'module' => 'views',
// This just tells our themes are elsewhere.
'row' => array( 'row' => array(
'aggregator_rss' => array( 'aggregator_rss' => array(
'title' => t('Aggregator item'), 'title' => t('Aggregator item'),
'help' => t('Display the aggregator item using the data from the original source.'), 'help' => t('Display the aggregator item using the data from the original source.'),
'handler' => 'views_plugin_row_aggregator_rss', 'handler' => 'views_plugin_row_aggregator_rss',
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules 'path' => drupal_get_path('module', 'views') . '/modules/node',
// Not necessary for most modules.
'theme' => 'views_view_row_rss', 'theme' => 'views_view_row_rss',
'base' => array('aggregator_item'), // only works with 'node' as base. 'base' => array('aggregator_item'),
// Only works with 'node' as base.
'uses options' => TRUE, 'uses options' => TRUE,
'type' => 'feed', 'type' => 'feed',
'help topic' => 'style-aggregator-rss', 'help topic' => 'style-aggregator-rss',

View File

@ -11,10 +11,11 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_aggregator_category_cid extends views_handler_argument_numeric { class views_handler_argument_aggregator_category_cid extends views_handler_argument_numeric {
/** /**
* Override the behavior of title(). Get the title of the category. * Override the behavior of title(). Get the title of the category.
*/ */
function title_query() { public function title_query() {
$titles = array(); $titles = array();
$result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN (:cid)", array(':cid' => $this->value)); $result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN (:cid)", array(':cid' => $this->value));
@ -23,4 +24,5 @@ class views_handler_argument_aggregator_category_cid extends views_handler_argum
} }
return $titles; return $titles;
} }
} }

View File

@ -11,10 +11,11 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_aggregator_fid extends views_handler_argument_numeric { class views_handler_argument_aggregator_fid extends views_handler_argument_numeric {
/** /**
* Override the behavior of title(). Get the title of the feed. * Override the behavior of title(). Get the title of the feed.
*/ */
function title_query() { public function title_query() {
$titles = array(); $titles = array();
$result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN (:fids)", array(':fids' => $this->value)); $result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN (:fids)", array(':fids' => $this->value));
@ -23,4 +24,5 @@ class views_handler_argument_aggregator_fid extends views_handler_argument_numer
} }
return $titles; return $titles;
} }
} }

View File

@ -11,10 +11,11 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_aggregator_iid extends views_handler_argument_numeric { class views_handler_argument_aggregator_iid extends views_handler_argument_numeric {
/** /**
* Override the behavior of title(). Get the title of the category. * Override the behavior of title(). Get the title of the category.
*/ */
function title_query() { public function title_query() {
$titles = array(); $titles = array();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d')); $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
@ -27,4 +28,5 @@ class views_handler_argument_aggregator_iid extends views_handler_argument_numer
} }
return $titles; return $titles;
} }
} }

View File

@ -12,15 +12,19 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_aggregator_category extends views_handler_field { class views_handler_field_aggregator_category extends views_handler_field {
/** /**
* Constructor to provide additional field to add. * Constructor to provide additional field to add.
*/ */
function construct() { public function construct() {
parent::construct(); parent::construct();
$this->additional_fields['cid'] = 'cid'; $this->additional_fields['cid'] = 'cid';
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE); $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
return $options; return $options;
@ -29,7 +33,7 @@ class views_handler_field_aggregator_category extends views_handler_field {
/** /**
* Provide link to category option * Provide link to category option
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
$form['link_to_category'] = array( $form['link_to_category'] = array(
'#title' => t('Link this field to its aggregator category page'), '#title' => t('Link this field to its aggregator category page'),
'#description' => t('This will override any other link you have set.'), '#description' => t('This will override any other link you have set.'),
@ -44,7 +48,7 @@ class views_handler_field_aggregator_category extends views_handler_field {
* *
* Data should be made XSS safe prior to calling this function. * Data should be made XSS safe prior to calling this function.
*/ */
function render_link($data, $values) { public function render_link($data, $values) {
$cid = $this->get_value($values, 'cid'); $cid = $this->get_value($values, 'cid');
if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
@ -53,8 +57,12 @@ class views_handler_field_aggregator_category extends views_handler_field {
return $data; return $data;
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values); return $this->render_link($this->sanitize_value($value), $values);
} }
} }

View File

@ -6,18 +6,25 @@
*/ */
/** /**
* Field handler that turns an item's title into a clickable link to the original * Field handler that turns an item's title into a clickable link to the
* source article. * original source article.
* *
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_aggregator_title_link extends views_handler_field { class views_handler_field_aggregator_title_link extends views_handler_field {
function construct() {
/**
* {@inheritdoc}
*/
public function construct() {
parent::construct(); parent::construct();
$this->additional_fields['link'] = 'link'; $this->additional_fields['link'] = 'link';
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE); $options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
@ -28,7 +35,7 @@ class views_handler_field_aggregator_title_link extends views_handler_field {
/** /**
* Provide link to the page being visited. * Provide link to the page being visited.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
$form['display_as_link'] = array( $form['display_as_link'] = array(
'#title' => t('Display as link'), '#title' => t('Display as link'),
'#type' => 'checkbox', '#type' => 'checkbox',
@ -37,12 +44,18 @@ class views_handler_field_aggregator_title_link extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values); return $this->render_link($this->sanitize_value($value), $values);
} }
function render_link($data, $values) { /**
* {@inheritdoc}
*/
public function render_link($data, $values) {
$link = $this->get_value($values, 'link'); $link = $this->get_value($values, 'link');
if (!empty($this->options['display_as_link'])) { if (!empty($this->options['display_as_link'])) {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
@ -52,4 +65,5 @@ class views_handler_field_aggregator_title_link extends views_handler_field {
return $data; return $data;
} }
} }

View File

@ -11,8 +11,13 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_aggregator_xss extends views_handler_field { class views_handler_field_aggregator_xss extends views_handler_field {
function render($values) {
/**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return aggregator_filter_xss($value); return aggregator_filter_xss($value);
} }
} }

View File

@ -11,7 +11,11 @@
* @ingroup views_filter_handlers * @ingroup views_filter_handlers
*/ */
class views_handler_filter_aggregator_category_cid extends views_handler_filter_in_operator { class views_handler_filter_aggregator_category_cid extends views_handler_filter_in_operator {
function get_value_options() {
/**
* {@inheritdoc}
*/
public function get_value_options() {
if (isset($this->value_options)) { if (isset($this->value_options)) {
return; return;
} }
@ -23,4 +27,5 @@ class views_handler_filter_aggregator_category_cid extends views_handler_filter_
$this->value_options[$category->cid] = $category->title; $this->value_options[$category->cid] = $category->title;
} }
} }
} }

View File

@ -2,17 +2,28 @@
/** /**
* @file * @file
* Contains the Aggregator Item RSS row style plugin. * Definition of views_plugin_row_aggregator_rss.
*/ */
/** /**
* Plugin which loads an aggregator item and formats it as an RSS item. * Plugin which loads an aggregator item and formats it as an RSS item.
*/ */
class views_plugin_row_aggregator_rss extends views_plugin_row { class views_plugin_row_aggregator_rss extends views_plugin_row {
var $base_table = 'aggregator_item';
var $base_field = 'iid';
function option_definition() { /**
*
*/
public $base_table = 'aggregator_item';
/**
*
*/
public $base_field = 'iid';
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['item_length'] = array('default' => 'default'); $options['item_length'] = array('default' => 'default');
@ -20,7 +31,10 @@ class views_plugin_row_aggregator_rss extends views_plugin_row {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* {@inheritdoc}
*/
public function options_form(&$form, &$form_state) {
$form['item_length'] = array( $form['item_length'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Display type'), '#title' => t('Display type'),
@ -34,7 +48,10 @@ class views_plugin_row_aggregator_rss extends views_plugin_row {
); );
} }
function render($row) { /**
* {@inheritdoc}
*/
public function render($row) {
$iid = $row->{$this->field_alias}; $iid = $row->{$this->field_alias};
$sql = "SELECT ai.iid, ai.fid, ai.title, ai.link, ai.author, ai.description, "; $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 .= "ai.timestamp, ai.guid, af.title AS feed_title, ai.link AS feed_LINK ";
@ -71,4 +88,5 @@ class views_plugin_row_aggregator_rss extends views_plugin_row {
'row' => $item 'row' => $item
)); ));
} }
} }

View File

@ -12,8 +12,7 @@
*/ */
function book_views_data() { function book_views_data() {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// book table // 'book' table.
$data['book']['table']['group'] = t('Book'); $data['book']['table']['group'] = t('Book');
$data['book']['table']['join'] = array( $data['book']['table']['join'] = array(
'node' => array( 'node' => array(
@ -35,8 +34,7 @@ function book_views_data() {
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// menu_links table -- this is aliased so we can get just book relations // 'menu_links' table -- this is aliased so we can get just book relations.
// Book hierarchy and weight data are now in {menu_links}. // Book hierarchy and weight data are now in {menu_links}.
$data['book_menu_links']['table']['group'] = t('Book'); $data['book_menu_links']['table']['group'] = t('Book');
$data['book_menu_links']['table']['join'] = array( $data['book_menu_links']['table']['join'] = array(
@ -87,9 +85,8 @@ function book_views_data() {
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// book_parent table -- this is an alias of the book table which // 'book_parent' table -- this is an alias of the book table which
// represents the parent book. // represents the parent book.
// The {book} record for the parent node. // The {book} record for the parent node.
$data['book_parent']['table']['group'] = t('Book'); $data['book_parent']['table']['group'] = t('Book');
$data['book_parent']['table']['join'] = array( $data['book_parent']['table']['join'] = array(
@ -119,13 +116,13 @@ function book_views_data() {
* Implements hook_views_plugins(). * Implements hook_views_plugins().
*/ */
function book_views_plugins() { function book_views_plugins() {
return array( return array(
'module' => 'views', 'module' => 'views',
'argument default' => array( 'argument default' => array(
'book_root' => array( 'book_root' => array(
'title' => t('Book root from current node'), 'title' => t('Book root from current node'),
'handler' => 'views_plugin_argument_default_book_root' 'handler' => 'views_plugin_argument_default_book_root',
), ),
), ),
); );
} }

View File

@ -1,14 +1,19 @@
<?php <?php
/** /**
* @file * @file
* Contains the book root from current node argument default plugin. * Definition of views_plugin_argument_default_book_root.
*/ */
/** /**
* Default argument plugin to get the current node's book root. * Default argument plugin to get the current node's book root.
*/ */
class views_plugin_argument_default_book_root extends views_plugin_argument_default_node { class views_plugin_argument_default_book_root extends views_plugin_argument_default_node {
function get_argument() {
/**
* {@inheritdoc}
*/
public function get_argument() {
// Use the argument_default_node plugin to get the nid argument. // Use the argument_default_node plugin to get the nid argument.
$nid = parent::get_argument(); $nid = parent::get_argument();
if (!empty($nid)) { if (!empty($nid)) {
@ -18,4 +23,5 @@ class views_plugin_argument_default_book_root extends views_plugin_argument_defa
} }
} }
} }
} }

View File

@ -10,13 +10,12 @@
/** /**
* Implements hook_views_data(). * Implements hook_views_data().
*/ */
function comment_views_data() { function comment_views_data() {
$data['comments']['moved to'] = 'comment'; $data['comments']['moved to'] = 'comment';
$data['comment']['comment']['moved to'] = array('field_data_comment_body', 'comment_body'); $data['comment']['comment']['moved to'] = array('field_data_comment_body', 'comment_body');
$data['comment']['comment']['field']['moved to'] = array('field_data_comment_body', 'comment_body'); $data['comment']['comment']['field']['moved to'] = array('field_data_comment_body', 'comment_body');
// Define the base group of this table. Fields that don't // Define the base group of this table. Fields that don't have a group
// have a group defined will go into this field by default. // defined will go into this field by default.
$data['comment']['table']['group'] = t('Comment'); $data['comment']['table']['group'] = t('Comment');
$data['comment']['table']['base'] = array( $data['comment']['table']['base'] = array(
@ -36,9 +35,8 @@ function comment_views_data() {
); );
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// Fields // Fields.
// Subject.
// subject
$data['comment']['subject'] = array( $data['comment']['subject'] = array(
'title' => t('Title'), 'title' => t('Title'),
'help' => t('The title of the comment.'), 'help' => t('The title of the comment.'),
@ -57,7 +55,7 @@ function comment_views_data() {
), ),
); );
// cid // Comment ID / 'cid'.
$data['comment']['cid'] = array( $data['comment']['cid'] = array(
'title' => t('ID'), 'title' => t('ID'),
'help' => t('The comment ID of the field'), 'help' => t('The comment ID of the field'),
@ -76,7 +74,7 @@ function comment_views_data() {
), ),
); );
// name (of comment author) // Username of the comment author.
$data['comment']['name'] = array( $data['comment']['name'] = array(
'title' => t('Author'), 'title' => t('Author'),
'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."), 'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."),
@ -95,7 +93,7 @@ function comment_views_data() {
), ),
); );
// homepage // Homepage.
$data['comment']['homepage'] = array( $data['comment']['homepage'] = array(
'title' => t("Author's website"), '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."), '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."),
@ -114,14 +112,14 @@ function comment_views_data() {
), ),
); );
// hostname // hostname.
$data['comment']['hostname'] = array( $data['comment']['hostname'] = array(
'title' => t('Hostname'), 'title' => t('Hostname'),
'help' => t('Hostname of user that posted the comment.'), 'help' => t('Hostname of user that posted the comment.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field', 'handler' => 'views_handler_field',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
@ -133,14 +131,14 @@ function comment_views_data() {
), ),
); );
// mail // Email address.
$data['comment']['mail'] = array( $data['comment']['mail'] = array(
'title' => t('Mail'), 'title' => t('Mail'),
'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'), 'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'),
'field' => array( 'field' => array(
'handler' => 'views_handler_field', 'handler' => 'views_handler_field',
'click sortable' => TRUE, 'click sortable' => TRUE,
), ),
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'views_handler_filter_string',
), ),
@ -152,7 +150,7 @@ function comment_views_data() {
), ),
); );
// created (when comment was posted) // Created - when comment was posted.
$data['comment']['created'] = array( $data['comment']['created'] = array(
'title' => t('Post date'), 'title' => t('Post date'),
'help' => t('Date and time of when the comment was created.'), 'help' => t('Date and time of when the comment was created.'),
@ -222,7 +220,7 @@ function comment_views_data() {
), ),
); );
// Language field // Language field.
if (module_exists('locale')) { if (module_exists('locale')) {
$data['comment']['language'] = array( $data['comment']['language'] = array(
'title' => t('Language'), 'title' => t('Language'),
@ -244,7 +242,7 @@ function comment_views_data() {
} }
$data['comments']['timestamp']['moved to'] = array('comment', 'changed'); $data['comments']['timestamp']['moved to'] = array('comment', 'changed');
// changed (when comment was last updated) // Changed (when comment was last updated).
$data['comment']['changed'] = array( $data['comment']['changed'] = array(
'title' => t('Updated date'), 'title' => t('Updated date'),
'help' => t('Date and time of when the comment was last updated.'), 'help' => t('Date and time of when the comment was last updated.'),
@ -320,7 +318,7 @@ function comment_views_data() {
), ),
); );
// status (approved or not) // Status (approved or not).
$data['comment']['status'] = array( $data['comment']['status'] = array(
'title' => t('Approved'), 'title' => t('Approved'),
'help' => t('Whether the comment is approved (or still in the moderation queue).'), 'help' => t('Whether the comment is approved (or still in the moderation queue).'),
@ -341,7 +339,7 @@ function comment_views_data() {
), ),
); );
// link to view comment // Link to view comment.
$data['comment']['view_comment'] = array( $data['comment']['view_comment'] = array(
'field' => array( 'field' => array(
'title' => t('View link'), 'title' => t('View link'),
@ -350,7 +348,7 @@ function comment_views_data() {
), ),
); );
// link to edit comment // Link to edit comment.
$data['comment']['edit_comment'] = array( $data['comment']['edit_comment'] = array(
'field' => array( 'field' => array(
'title' => t('Edit link'), 'title' => t('Edit link'),
@ -359,7 +357,7 @@ function comment_views_data() {
), ),
); );
// link to delete comment // Link to delete comment.
$data['comment']['delete_comment'] = array( $data['comment']['delete_comment'] = array(
'field' => array( 'field' => array(
'title' => t('Delete link'), 'title' => t('Delete link'),
@ -368,8 +366,7 @@ function comment_views_data() {
), ),
); );
// Link to approve comment.
// link to approve comment
$data['comment']['approve_comment'] = array( $data['comment']['approve_comment'] = array(
'field' => array( 'field' => array(
'title' => t('Approve link'), 'title' => t('Approve link'),
@ -378,7 +375,7 @@ function comment_views_data() {
), ),
); );
// link to reply to comment // Link to reply to comment.
$data['comment']['replyto_comment'] = array( $data['comment']['replyto_comment'] = array(
'field' => array( 'field' => array(
'title' => t('Reply-to link'), 'title' => t('Reply-to link'),
@ -461,22 +458,21 @@ function comment_views_data() {
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// node_comment_statistics table // 'node_comment_statistics' table.
// Define the group.
// define the group
$data['node_comment_statistics']['table']['group'] = t('Content'); $data['node_comment_statistics']['table']['group'] = t('Content');
// joins // Joins.
$data['node_comment_statistics']['table']['join'] = array( $data['node_comment_statistics']['table']['join'] = array(
//...to the node table // ...to the node table.
'node' => array( 'node' => array(
'type' => 'INNER', 'type' => 'INNER',
'left_field' => 'nid', 'left_field' => 'nid',
'field' => 'nid', 'field' => 'nid',
), ),
); );
// last_comment_timestamp // Timestamp of the last comment.
$data['node_comment_statistics']['last_comment_timestamp'] = array( $data['node_comment_statistics']['last_comment_timestamp'] = array(
'title' => t('Last comment time'), 'title' => t('Last comment time'),
'help' => t('Date and time of when the last comment was posted.'), 'help' => t('Date and time of when the last comment was posted.'),
@ -492,7 +488,7 @@ function comment_views_data() {
), ),
); );
// last_comment_name (author's name) // Last comment author's username.
$data['node_comment_statistics']['last_comment_name'] = array( $data['node_comment_statistics']['last_comment_name'] = array(
'title' => t("Last comment author"), 'title' => t("Last comment author"),
'help' => t('The name of the author of the last posted comment.'), 'help' => t('The name of the author of the last posted comment.'),
@ -507,7 +503,7 @@ function comment_views_data() {
), ),
); );
// comment_count // Comment count.
$data['node_comment_statistics']['comment_count'] = array( $data['node_comment_statistics']['comment_count'] = array(
'title' => t('Comment count'), 'title' => t('Comment count'),
'help' => t('The number of comments a node has.'), 'help' => t('The number of comments a node has.'),
@ -526,7 +522,7 @@ function comment_views_data() {
), ),
); );
// last_comment_timestamp // Timestamp of when the last comment update happened.
$data['node_comment_statistics']['last_updated'] = array( $data['node_comment_statistics']['last_updated'] = array(
'title' => t('Updated/commented date'), 'title' => t('Updated/commented date'),
'help' => t('The most recent of last comment posted or node updated time.'), 'help' => t('The most recent of last comment posted or node updated time.'),
@ -558,7 +554,7 @@ function comment_views_data() {
), ),
); );
// last_comment_uid // The user ID / 'uid' of the user who last posted a comment.
$data['node_comment_statistics']['last_comment_uid'] = array( $data['node_comment_statistics']['last_comment_uid'] = array(
'title' => t('Last comment uid'), 'title' => t('Last comment uid'),
'help' => t('The User ID of the author of the last comment of a node.'), 'help' => t('The User ID of the author of the last comment of a node.'),
@ -584,11 +580,12 @@ function comment_views_data() {
} }
/** /**
* Use views_data_alter to add items to the node table that are * Implements hook_views_data_alter() on behalf of comment.module.
* relevant to comments. *
* Add items to the node table that are relevant to comments.
*/ */
function comment_views_data_alter(&$data) { function comment_views_data_alter(&$data) {
// new comments // New comments.
$data['node']['new_comments'] = array( $data['node']['new_comments'] = array(
'title' => t('New comments'), 'title' => t('New comments'),
'help' => t('The number of new comments on the node.'), 'help' => t('The number of new comments on the node.'),
@ -606,7 +603,7 @@ function comment_views_data_alter(&$data) {
), ),
); );
// Comment status of the node // Comment status of the node.
$data['node']['comment'] = array( $data['node']['comment'] = array(
'title' => t('Comment status'), 'title' => t('Comment status'),
'help' => t('Whether comments are enabled or disabled on the node.'), 'help' => t('Whether comments are enabled or disabled on the node.'),
@ -636,7 +633,7 @@ function comment_views_data_alter(&$data) {
'field' => 'uid', 'field' => 'uid',
'name table' => 'users', 'name table' => 'users',
'name field' => 'name', 'name field' => 'name',
'handler' => 'views_handler_filter_comment_user_uid' 'handler' => 'views_handler_filter_comment_user_uid',
), ),
); );
@ -652,7 +649,6 @@ function comment_views_data_alter(&$data) {
'handler' => 'views_handler_relationship', 'handler' => 'views_handler_relationship',
), ),
); );
} }
/** /**
@ -667,8 +663,10 @@ function comment_views_plugins() {
'help' => t('Display the comment with standard comment view.'), 'help' => t('Display the comment with standard comment view.'),
'handler' => 'views_plugin_row_comment_view', 'handler' => 'views_plugin_row_comment_view',
'theme' => 'views_view_row_comment', 'theme' => 'views_view_row_comment',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules 'path' => drupal_get_path('module', 'views') . '/modules/comment',
'base' => array('comment'), // only works with 'comment' as base. // Not necessary for most modules.
'base' => array('comment'),
// Only works with 'comment' as base.
'uses options' => TRUE, 'uses options' => TRUE,
'type' => 'normal', 'type' => 'normal',
'help topic' => 'style-comment', 'help topic' => 'style-comment',
@ -678,8 +676,10 @@ function comment_views_plugins() {
'help' => t('Display the comment as RSS.'), 'help' => t('Display the comment as RSS.'),
'handler' => 'views_plugin_row_comment_rss', 'handler' => 'views_plugin_row_comment_rss',
'theme' => 'views_view_row_rss', 'theme' => 'views_view_row_rss',
'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules 'path' => drupal_get_path('module', 'views') . '/modules/comment',
'base' => array('comment'), // only works with 'comment' as base. // Not necessary for most modules.
'base' => array('comment'),
// Only works with 'comment' as base.
'uses options' => TRUE, 'uses options' => TRUE,
'type' => 'feed', 'type' => 'feed',
'help topic' => 'style-comment-rss', 'help topic' => 'style-comment-rss',
@ -689,7 +689,7 @@ function comment_views_plugins() {
} }
/** /**
* Template helper for theme_views_view_row_comment * Template helper for theme_views_view_row_comment.
*/ */
function template_preprocess_views_view_row_comment(&$vars) { function template_preprocess_views_view_row_comment(&$vars) {
$options = $vars['options']; $options = $vars['options'];
@ -701,9 +701,9 @@ function template_preprocess_views_view_row_comment(&$vars) {
$node->view = &$view; $node->view = &$view;
$build = comment_view_multiple(array($comment->cid => $comment), $node, $plugin->options['view_mode']); $build = comment_view_multiple(array($comment->cid => $comment), $node, $plugin->options['view_mode']);
// If we're displaying the comments without links, remove them from the // If displaying the comments without links, remove them from the renderable
// renderable array. There is no way to avoid building them in the first // array; there is no way to avoid building them in the first place.
// place (see comment_build_content()). // @see comment_build_content()
if (empty($options['links'])) { if (empty($options['links'])) {
foreach ($build as $cid => &$comment_build) { foreach ($build as $cid => &$comment_build) {
if (isset($comment_build['links'])) { if (isset($comment_build['links'])) {

View File

@ -6,12 +6,12 @@
*/ */
/** /**
* Implementation of hook_views_default_views() * Implements hook_views_default_views().
*/ */
function comment_views_default_views() { function comment_views_default_views() {
$views = array(); $views = array();
$view = new view; $view = new view();
$view->name = 'comments_recent'; $view->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->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->tag = 'default';
@ -122,7 +122,7 @@ function comment_views_default_views() {
$views['comments_recent'] = $view; $views['comments_recent'] = $view;
$view = new view; $view = new view();
$view->name = 'tracker'; $view->name = 'tracker';
$view->description = 'Shows all new activity on system.'; $view->description = 'Shows all new activity on system.';
$view->tag = 'default'; $view->tag = 'default';

View File

@ -12,7 +12,11 @@
* @ingroup views_argument_handlers * @ingroup views_argument_handlers
*/ */
class views_handler_argument_comment_user_uid extends views_handler_argument { class views_handler_argument_comment_user_uid extends views_handler_argument {
function title() {
/**
* {@inheritdoc}
*/
public function title() {
if (!$this->argument) { if (!$this->argument) {
$title = variable_get('anonymous', t('Anonymous')); $title = variable_get('anonymous', t('Anonymous'));
} }
@ -26,7 +30,10 @@ class views_handler_argument_comment_user_uid extends views_handler_argument {
return check_plain($title); return check_plain($title);
} }
function default_actions($which = NULL) { /**
* {@inheritdoc}
*/
public function default_actions($which = NULL) {
// Disallow summary views on this argument. // Disallow summary views on this argument.
if (!$which) { if (!$which) {
$actions = parent::default_actions(); $actions = parent::default_actions();
@ -40,7 +47,10 @@ class views_handler_argument_comment_user_uid extends views_handler_argument {
} }
} }
function query($group_by = FALSE) { /**
* {@inheritdoc}
*/
public function query($group_by = FALSE) {
$this->ensure_my_table(); $this->ensure_my_table();
$subselect = db_select('comment', 'c'); $subselect = db_select('comment', 'c');
@ -55,7 +65,11 @@ class views_handler_argument_comment_user_uid extends views_handler_argument {
$this->query->add_where(0, $condition); $this->query->add_where(0, $condition);
} }
function get_sort_name() { /**
* {@inheritdoc}
*/
public function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order')); return t('Numerical', array(), array('context' => 'Sort order'));
} }
} }

View File

@ -11,10 +11,11 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_comment extends views_handler_field { class views_handler_field_comment extends views_handler_field {
/** /**
* Override init function to provide generic option to link to comment. * Override init function to provide generic option to link to comment.
*/ */
function init(&$view, &$options) { public function init(&$view, &$options) {
parent::init($view, $options); parent::init($view, $options);
if (!empty($this->options['link_to_comment'])) { if (!empty($this->options['link_to_comment'])) {
$this->additional_fields['cid'] = 'cid'; $this->additional_fields['cid'] = 'cid';
@ -22,7 +23,10 @@ class views_handler_field_comment extends views_handler_field {
} }
} }
function option_definition() { /**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE); $options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE); $options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
@ -31,9 +35,9 @@ class views_handler_field_comment extends views_handler_field {
} }
/** /**
* Provide link-to-comment option * Provide link-to-comment option.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array( $form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'), '#title' => t('Link this field to its comment'),
'#description' => t("Enable to override this field's links."), '#description' => t("Enable to override this field's links."),
@ -48,7 +52,10 @@ class views_handler_field_comment extends views_handler_field {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
} }
function render_link($data, $values) { /**
* {@inheritdoc}
*/
public function render_link($data, $values) {
if (!empty($this->options['link_to_comment'])) { if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
$nid = $this->get_value($values, 'nid'); $nid = $this->get_value($values, 'nid');
@ -58,7 +65,7 @@ class views_handler_field_comment extends views_handler_field {
$this->options['alter']['fragment'] = "comment-" . $cid; $this->options['alter']['fragment'] = "comment-" . $cid;
} }
// If there is no comment link to the node. // If there is no comment link to the node.
else if ($this->options['link_to_node']) { elseif ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid; $this->options['alter']['path'] = "node/" . $nid;
} }
} }
@ -66,8 +73,12 @@ class views_handler_field_comment extends views_handler_field {
return $data; return $data;
} }
function render($values) { /**
* {@inheritdoc}
*/
public function render($values) {
$value = $this->get_value($values); $value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values); return $this->render_link($this->sanitize_value($value), $values);
} }
} }

View File

@ -11,11 +11,13 @@
* @ingroup views_field_handlers * @ingroup views_field_handlers
*/ */
class views_handler_field_comment_depth extends views_handler_field { class views_handler_field_comment_depth extends views_handler_field {
/** /**
* Work out the depth of this comment * Work out the depth of this comment.
*/ */
function render($values) { public function render($values) {
$comment_thread = $this->get_value($values); $comment_thread = $this->get_value($values);
return count(explode('.', $comment_thread)) - 1; return count(explode('.', $comment_thread)) - 1;
} }
} }

Some files were not shown because too many files have changed in this diff Show More