Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
date_ical
Commits
7cb3e411
Commit
7cb3e411
authored
Sep 08, 2015
by
Robert Rollins
Browse files
Some whitespace changes.
parent
63c03a44
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
31 deletions
+31
-31
includes/date_ical_plugin_row_ical_entity.inc
includes/date_ical_plugin_row_ical_entity.inc
+31
-31
No files found.
includes/date_ical_plugin_row_ical_entity.inc
View file @
7cb3e411
...
@@ -9,14 +9,14 @@
...
@@ -9,14 +9,14 @@
* A Views plugin which builds an iCal VEVENT from a single node.
* A Views plugin which builds an iCal VEVENT from a single node.
*/
*/
class
date_ical_plugin_row_ical_entity
extends
views_plugin_row
{
class
date_ical_plugin_row_ical_entity
extends
views_plugin_row
{
// Basic properties that let the row style follow relationships.
// Basic properties that let the row style follow relationships.
protected
$base_table
=
'node'
;
protected
$base_table
=
'node'
;
protected
$base_field
=
'nid'
;
protected
$base_field
=
'nid'
;
// Stores the nodes loaded with pre_render.
// Stores the nodes loaded with pre_render.
protected
$entities
=
array
();
protected
$entities
=
array
();
/**
/**
* Initialize the row plugin.
* Initialize the row plugin.
*/
*/
...
@@ -25,7 +25,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -25,7 +25,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$this
->
base_table
=
$view
->
base_table
;
$this
->
base_table
=
$view
->
base_table
;
$this
->
base_field
=
$view
->
base_field
;
$this
->
base_field
=
$view
->
base_field
;
}
}
/**
/**
* Set up the options for the row plugin.
* Set up the options for the row plugin.
*/
*/
...
@@ -36,13 +36,13 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -36,13 +36,13 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$options
[
'location_field'
]
=
array
(
'default'
=>
array
());
$options
[
'location_field'
]
=
array
(
'default'
=>
array
());
return
$options
;
return
$options
;
}
}
/**
/**
* Build the form for setting the row plugin's options.
* Build the form for setting the row plugin's options.
*/
*/
public
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
);
// Build the select dropdown for the Date field that the user wants to use
// Build the select dropdown for the Date field that the user wants to use
// to populate the date properties in VEVENTs.
// to populate the date properties in VEVENTs.
$data
=
date_views_fields
(
$this
->
base_table
);
$data
=
date_views_fields
(
$this
->
base_table
);
...
@@ -71,7 +71,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -71,7 +71,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
<br>To change the iCal view mode, configure it on the 'Manage Display' page for each Content Type.
<br>To change the iCal view mode, configure it on the 'Manage Display' page for each Content Type.
Please note that all HTML will be stripped from the output, to comply with iCal standards."
),
Please note that all HTML will be stripped from the output, to comply with iCal standards."
),
);
);
// Build the select dropdown for the text/node_reference field that the user
// Build the select dropdown for the text/node_reference field that the user
// wants to use to (optionally) populate the SUMMARY.
// wants to use to (optionally) populate the SUMMARY.
$summary_fields
=
date_ical_get_summary_fields
(
$this
->
base_table
);
$summary_fields
=
date_ical_get_summary_fields
(
$this
->
base_table
);
...
@@ -88,7 +88,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -88,7 +88,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
Choose which text, taxonomy term reference or Node Reference field you would like to be output as the SUMMARY.
Choose which text, taxonomy term reference or Node Reference field you would like to be output as the SUMMARY.
If using a Node Reference, the Title of the referenced node will be used.'
),
If using a Node Reference, the Title of the referenced node will be used.'
),
);
);
// Build the select dropdown for the text/node_reference field that the user
// Build the select dropdown for the text/node_reference field that the user
// wants to use to (optionally) populate the LOCATION.
// wants to use to (optionally) populate the LOCATION.
$location_fields
=
date_ical_get_location_fields
(
$this
->
base_table
);
$location_fields
=
date_ical_get_location_fields
(
$this
->
base_table
);
...
@@ -106,7 +106,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -106,7 +106,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
If using a Node Reference, the Title of the referenced node will be used.'
),
If using a Node Reference, the Title of the referenced node will be used.'
),
);
);
}
}
/**
/**
* Preload the list of entities which will appear in the view.
* Preload the list of entities which will appear in the view.
*
*
...
@@ -123,7 +123,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -123,7 +123,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
foreach
(
$values
as
$row
)
{
foreach
(
$values
as
$row
)
{
// Use the $id as the key so we create only value per entity.
// Use the $id as the key so we create only value per entity.
$id
=
$row
->
{
$this
->
field_alias
};
$id
=
$row
->
{
$this
->
field_alias
};
// Node revisions need special loading.
// Node revisions need special loading.
if
(
$this
->
view
->
base_table
==
'node_revision'
)
{
if
(
$this
->
view
->
base_table
==
'node_revision'
)
{
$this
->
entities
[
$id
]
=
node_load
(
NULL
,
$id
);
$this
->
entities
[
$id
]
=
node_load
(
NULL
,
$id
);
...
@@ -134,13 +134,13 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -134,13 +134,13 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$ids
[
$id
]
=
$id
;
$ids
[
$id
]
=
$id
;
}
}
}
}
$base_tables
=
date_views_base_tables
();
$base_tables
=
date_views_base_tables
();
$this
->
entity_type
=
$base_tables
[
$this
->
view
->
base_table
];
$this
->
entity_type
=
$base_tables
[
$this
->
view
->
base_table
];
if
(
!
empty
(
$ids
))
{
if
(
!
empty
(
$ids
))
{
$this
->
entities
=
entity_load
(
$this
->
entity_type
,
$ids
);
$this
->
entities
=
entity_load
(
$this
->
entity_type
,
$ids
);
}
}
// Get the language for this view.
// Get the language for this view.
$this
->
language
=
$this
->
display
->
handler
->
get_option
(
'field_language'
);
$this
->
language
=
$this
->
display
->
handler
->
get_option
(
'field_language'
);
$substitutions
=
views_views_query_substitutions
(
$this
->
view
);
$substitutions
=
views_views_query_substitutions
(
$this
->
view
);
...
@@ -148,7 +148,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -148,7 +148,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$this
->
language
=
$substitutions
[
$this
->
language
];
$this
->
language
=
$substitutions
[
$this
->
language
];
}
}
}
}
/**
/**
* Renders the entities returned by the view into event arrays.
* Renders the entities returned by the view into event arrays.
*/
*/
...
@@ -157,32 +157,32 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -157,32 +157,32 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if
(
!
is_numeric
(
$id
))
{
if
(
!
is_numeric
(
$id
))
{
return
NULL
;
return
NULL
;
}
}
// Load the specified entity:
// Load the specified entity:
$entity
=
$this
->
entities
[
$id
];
$entity
=
$this
->
entities
[
$id
];
if
(
empty
(
$entity
))
{
if
(
empty
(
$entity
))
{
// This can happen when an RRULE is involved.
// This can happen when an RRULE is involved.
return
NULL
;
return
NULL
;
}
}
$date_fields
=
date_views_fields
(
$this
->
base_table
);
$date_fields
=
date_views_fields
(
$this
->
base_table
);
$date_info
=
$date_fields
[
'name'
][
$this
->
options
[
'date_field'
]];
$date_info
=
$date_fields
[
'name'
][
$this
->
options
[
'date_field'
]];
$field_name
=
str_replace
(
array
(
'_value'
,
'_value2'
),
''
,
$date_info
[
'real_field_name'
]);
$field_name
=
str_replace
(
array
(
'_value'
,
'_value2'
),
''
,
$date_info
[
'real_field_name'
]);
$delta_field
=
$date_info
[
'delta_field'
];
$delta_field
=
$date_info
[
'delta_field'
];
$is_field
=
$date_info
[
'is_field'
];
$is_field
=
$date_info
[
'is_field'
];
// Sometimes the timestamp is actually the revision timestamp.
// Sometimes the timestamp is actually the revision timestamp.
if
(
$this
->
view
->
base_table
==
'node_revision'
&&
$field_name
==
'timestamp'
)
{
if
(
$this
->
view
->
base_table
==
'node_revision'
&&
$field_name
==
'timestamp'
)
{
$field_name
=
'revision_timestamp'
;
$field_name
=
'revision_timestamp'
;
}
}
if
(
!
isset
(
$entity
->
$field_name
))
{
if
(
!
isset
(
$entity
->
$field_name
))
{
// This entity doesn't have the date property that the user configured
// This entity doesn't have the date property that the user configured
// our view to use. We can't do anything with it.
// our view to use. We can't do anything with it.
return
NULL
;
return
NULL
;
}
}
$date_field
=
$entity
->
$field_name
;
$date_field
=
$entity
->
$field_name
;
// Pull the date value from the specified field of the entity.
// Pull the date value from the specified field of the entity.
$entity
->
date_id
=
array
();
$entity
->
date_id
=
array
();
$start
=
NULL
;
$start
=
NULL
;
...
@@ -199,7 +199,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -199,7 +199,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
global
$base_url
;
global
$base_url
;
$domain
=
preg_replace
(
'#^https?://#'
,
''
,
$base_url
);
$domain
=
preg_replace
(
'#^https?://#'
,
''
,
$base_url
);
$entity
->
date_id
[]
=
"calendar.
$id
.
$field_name
.
$delta
@
$domain
"
;
$entity
->
date_id
[]
=
"calendar.
$id
.
$field_name
.
$delta
@
$domain
"
;
if
(
!
empty
(
$date_field
[
'value'
]))
{
if
(
!
empty
(
$date_field
[
'value'
]))
{
$start
=
new
DateObject
(
$date_field
[
'value'
],
$date_field
[
'timezone_db'
]);
$start
=
new
DateObject
(
$date_field
[
'value'
],
$date_field
[
'timezone_db'
]);
if
(
!
empty
(
$date_field
[
'value2'
]))
{
if
(
!
empty
(
$date_field
[
'value2'
]))
{
...
@@ -214,32 +214,32 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -214,32 +214,32 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$start
=
new
DateObject
(
$date_field
,
$date_field
[
'timezone_db'
]);
$start
=
new
DateObject
(
$date_field
,
$date_field
[
'timezone_db'
]);
$end
=
new
DateObject
(
$date_field
,
$date_field
[
'timezone_db'
]);
$end
=
new
DateObject
(
$date_field
,
$date_field
[
'timezone_db'
]);
}
}
// Set the item date to the proper display timezone.
// Set the item date to the proper display timezone.
$start
->
setTimezone
(
new
DateTimeZone
(
$date_field
[
'timezone'
]));
$start
->
setTimezone
(
new
DateTimeZone
(
$date_field
[
'timezone'
]));
$end
->
setTimezone
(
new
DateTimeZone
(
$date_field
[
'timezone'
]));
$end
->
setTimezone
(
new
DateTimeZone
(
$date_field
[
'timezone'
]));
// Check if the start and end dates indicate that this is an All Day event.
// Check if the start and end dates indicate that this is an All Day event.
$all_day
=
date_is_all_day
(
$all_day
=
date_is_all_day
(
date_format
(
$start
,
DATE_FORMAT_DATETIME
),
date_format
(
$start
,
DATE_FORMAT_DATETIME
),
date_format
(
$end
,
DATE_FORMAT_DATETIME
),
date_format
(
$end
,
DATE_FORMAT_DATETIME
),
date_granularity_precision
(
$date_info
[
'granularity'
])
date_granularity_precision
(
$date_info
[
'granularity'
])
);
);
if
(
$all_day
)
{
if
(
$all_day
)
{
// According to RFC 2445 (clarified in RFC 5545) the DTEND value is
// According to RFC 2445 (clarified in RFC 5545) the DTEND value is
// non-inclusive. When dealing with All Day values, they're DATEs rather
// non-inclusive. When dealing with All Day values, they're DATEs rather
// than DATETIMEs, so we need to add a day to conform to RFC.
// than DATETIMEs, so we need to add a day to conform to RFC.
$end
->
modify
(
"+1 day"
);
$end
->
modify
(
"+1 day"
);
}
}
// If the user specified a LOCATION field, pull that data from the entity.
// If the user specified a LOCATION field, pull that data from the entity.
$location
=
''
;
$location
=
''
;
if
(
!
empty
(
$this
->
options
[
'location_field'
])
&&
$this
->
options
[
'location_field'
]
!=
'none'
)
{
if
(
!
empty
(
$this
->
options
[
'location_field'
])
&&
$this
->
options
[
'location_field'
]
!=
'none'
)
{
$location_fields
=
date_ical_get_location_fields
(
$this
->
base_table
);
$location_fields
=
date_ical_get_location_fields
(
$this
->
base_table
);
$location_info
=
$location_fields
[
'name'
][
$this
->
options
[
'location_field'
]];
$location_info
=
$location_fields
[
'name'
][
$this
->
options
[
'location_field'
]];
$location_field_name
=
$location_info
[
'real_field_name'
];
$location_field_name
=
$location_info
[
'real_field_name'
];
// Only attempt this is the entity actually has this field.
// Only attempt this is the entity actually has this field.
$items
=
field_get_items
(
$this
->
entity_type
,
$entity
,
$location_field_name
);
$items
=
field_get_items
(
$this
->
entity_type
,
$entity
,
$location_field_name
);
if
(
$items
)
{
if
(
$items
)
{
...
@@ -286,7 +286,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -286,7 +286,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
}
}
}
}
}
}
// Create the rendered event using the display settings from the
// Create the rendered event using the display settings from the
// iCal view mode.
// iCal view mode.
$rendered_array
=
entity_view
(
$this
->
entity_type
,
array
(
$entity
),
'ical'
,
$this
->
language
,
TRUE
);
$rendered_array
=
entity_view
(
$this
->
entity_type
,
array
(
$entity
),
'ical'
,
$this
->
language
,
TRUE
);
...
@@ -336,7 +336,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -336,7 +336,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
'language'
=>
$this
->
language
,
'language'
=>
$this
->
language
,
);
);
drupal_alter
(
'date_ical_export_html'
,
$data
,
$this
->
view
,
$context
);
drupal_alter
(
'date_ical_export_html'
,
$data
,
$this
->
view
,
$context
);
$event
=
array
();
$event
=
array
();
$event
[
'summary'
]
=
date_ical_sanitize_text
(
$data
[
'summary'
]);
$event
[
'summary'
]
=
date_ical_sanitize_text
(
$data
[
'summary'
]);
$event
[
'description'
]
=
date_ical_sanitize_text
(
$data
[
'description'
]);
$event
[
'description'
]
=
date_ical_sanitize_text
(
$data
[
'description'
]);
...
@@ -350,18 +350,18 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -350,18 +350,18 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if
(
$location
)
{
if
(
$location
)
{
$event
[
'location'
]
=
date_ical_sanitize_text
(
$location
);
$event
[
'location'
]
=
date_ical_sanitize_text
(
$location
);
}
}
// For this event's UID, use either the date_id generated by the Date
// For this event's UID, use either the date_id generated by the Date
// module, or the event page's URL if the date_id isn't available.
// module, or the event page's URL if the date_id isn't available.
$event
[
'uid'
]
=
!
empty
(
$entity
->
date_id
)
?
$entity
->
date_id
[
0
]
:
$event
[
'url'
];
$event
[
'uid'
]
=
!
empty
(
$entity
->
date_id
)
?
$entity
->
date_id
[
0
]
:
$event
[
'url'
];
// If we are using a repeat rule (and not just multi-day events) we
// If we are using a repeat rule (and not just multi-day events) we
// remove the item from the entities list so that its VEVENT won't be
// remove the item from the entities list so that its VEVENT won't be
// re-created.
// re-created.
if
(
$event
[
'rrule'
])
{
if
(
$event
[
'rrule'
])
{
$this
->
entities
[
$id
]
=
NULL
;
$this
->
entities
[
$id
]
=
NULL
;
}
}
// According to the iCal standard, CREATED and LAST-MODIFIED must be UTC.
// According to the iCal standard, CREATED and LAST-MODIFIED must be UTC.
// Fortunately, Drupal stores timestamps in the DB as UTC, so we just need
// Fortunately, Drupal stores timestamps in the DB as UTC, so we just need
// to tell DateObject to treat the timestamp as UTC from the start.
// to tell DateObject to treat the timestamp as UTC from the start.
...
@@ -377,11 +377,11 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
...
@@ -377,11 +377,11 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
// If changed is unset, but created is, use that for last-modified.
// If changed is unset, but created is, use that for last-modified.
$event
[
'last-modified'
]
=
new
DateObject
(
$entity
->
created
,
'UTC'
);
$event
[
'last-modified'
]
=
new
DateObject
(
$entity
->
created
,
'UTC'
);
}
}
// Allow other modules to alter the structured event object, before it gets
// Allow other modules to alter the structured event object, before it gets
// passed to the style plugin to be converted into an iCalcreator vevent.
// passed to the style plugin to be converted into an iCalcreator vevent.
drupal_alter
(
'date_ical_export_raw_event'
,
$event
,
$this
->
view
,
$context
);
drupal_alter
(
'date_ical_export_raw_event'
,
$event
,
$this
->
view
,
$context
);
return
$event
;
return
$event
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment