Commit 537d70db authored by John Fiala's avatar John Fiala
Browse files

Issue #1674284 by sun, jcfiala: Cleaning up the code to Drupal standards.

parent 95e7983c
div.link-field-column {
.link-field-column {
float: left;
width: 48%;
}
div.link-field-column .form-text {
.link-field-column .form-text {
width: 95%;
}
......@@ -18,20 +18,21 @@ function link_field_schema($field) {
'columns' => array(
'url' => array(
'type' => 'varchar',
'length' => 2048, // Maximum URLs length.
// Maximum URLs length.
'length' => 2048,
'not null' => FALSE,
'sortable' => TRUE
'sortable' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE
'sortable' => TRUE,
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE
'not null' => FALSE,
),
),
);
......@@ -87,8 +88,7 @@ function link_update_7000() {
* Renames all displays from foobar to link_foobar
*/
function link_update_7001() {
// for each field that is a link field, we need to update the display types:
// Update the display type for each link field type.
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
foreach ($result as $field) {
$field_id = $field->id;
......@@ -102,13 +102,12 @@ function link_update_7001() {
$update_instance = FALSE;
foreach ($instance_data['display'] as $display_name => $display_data) {
if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
$instance_data['display'][$display_name]['type'] = 'link_'. $display_data['type'];
$instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
$update_instance = TRUE;
}
}
if ($update_instance) {
// update the database.
$num_updated = db_update('field_config_instance')
db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
......
......@@ -92,7 +92,7 @@ class MigrateLinkFieldHandler extends MigrateFieldHandler {
if (!is_array($arguments['title'])) {
$item['title'] = $arguments['title'];
}
else if (isset($arguments['title'][$delta])) {
elseif (isset($arguments['title'][$delta])) {
$item['title'] = $arguments['title'][$delta];
}
}
......
This diff is collapsed.
......@@ -144,6 +144,6 @@ class link_views_handler_argument_target extends views_handler_argument {
$this->ensure_my_table();
// Because attributes are stored serialized, our only option is to also
// serialize the data we're searching for and use LIKE to find similar data.
$this->query->add_where(0, $this->table_alias .'.'. $this->real_field ." LIKE '%%%s%'", serialize(array('target' => $this->argument)));
$this->query->add_where(0, $this->table_alias . '.' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
}
}
......@@ -80,27 +80,28 @@ class link_views_handler_filter_protocol extends views_handler_filter_string {
$where_conditions = array();
foreach ($protocols as $protocol) {
// Simple case, the URL begins with the specified protocol.
$condition = $field .' LIKE \''. $protocol .'%\'';
$condition = $field . ' LIKE \'' . $protocol . '%\'';
// More complex case, no protocol specified but is automatically cleaned up
// by link_cleanup_url(). RegEx is required for this search operation.
if ($protocol == 'http') {
$LINK_DOMAINS = _link_domains();
if ($db_type == 'pgsql') {
// PostGreSQL code has NOT been tested. Please report any problems to the link issue queue.
// pgSQL requires all slashes to be double escaped in regular expressions.
// See http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
$condition .= ' OR '. $field .' ~* \''.'^(([a-z0-9]([a-z0-9\\-_]*\\.)+)('. LINK_DOMAINS .'|[a-z][a-z]))'.'\'';
$condition .= ' OR ' . $field .' ~* \''.'^(([a-z0-9]([a-z0-9\\-_]*\\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
}
else {
// mySQL requires backslashes to be double (triple?) escaped within character classes.
// See http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_regexp
$condition .= ' OR '. $field .' REGEXP \''.'^(([a-z0-9]([a-z0-9\\\-_]*\.)+)('. LINK_DOMAINS .'|[a-z][a-z]))'.'\'';
$condition .= ' OR ' . $field . ' REGEXP \''.'^(([a-z0-9]([a-z0-9\\\-_]*\.)+)(' . $LINK_DOMAINS . '|[a-z][a-z]))' . '\'';
}
}
$where_conditions[] = $condition;
}
$this->query->add_where($this->options['group'], implode(' '. $this->operator .' ', $where_conditions));
$this->query->add_where($this->options['group'], implode(' ' . $this->operator . ' ', $where_conditions));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment