View source
<?php
define('iframe_EXTERNAL', 'external');
define('iframe_INTERNAL', 'internal');
define('iframe_FRONT', 'front');
define('iframe_EMAIL', 'email');
define('iframe_DOMAINS', 'aero|arpa|biz|com|cat|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobi|local');
if (!defined('DEBUG_LEVEL')) {
define('DEBUG_LEVEL', 0);
}
if (!function_exists('dmsg')) {
function dmsg($level, $text) {
if ($level <= DEBUG_LEVEL) {
error_log('iframe(' . $level . '): ' . $text);
}
}
}
function iframe_init() {
drupal_add_js(drupal_get_path('module', 'iframe') . '/iframe.js');
}
function iframe_field_info() {
dmsg(3, 'func iframe_field_info');
return array(
'iframe' => array(
'label' => t('IFrame'),
'description' => t('Store a title, src, and attributes in the database to assemble an iframe.'),
),
);
}
function iframe_field_settings($op, $field) {
dmsg(3, 'func iframe_field_settings op=' . $op);
switch ($op) {
case 'form':
$form = array(
'#theme' => 'iframe_field_settings',
);
$form['url'] = array(
'#type' => 'checkbox',
'#title' => t('Optional url'),
'#default_value' => $field['url'],
'#return_value' => 'optional',
'#description' => t('If checked, the url field is optional. If the url is ommitted, nothing will be displayed.'),
);
$title_options = array(
'optional' => t('Optional Title'),
'required' => t('Required Title'),
'value' => t('Static Title: '),
'none' => t('No Title'),
);
$form['title'] = array(
'#type' => 'radios',
'#title' => t('IFrame Title'),
'#default_value' => isset($field['title']) ? $field['title'] : 'optional',
'#options' => $title_options,
'#description' => t('If the iframe title is optional or required, a field will be displayed to the end user. If the iframe title is static, the iframe will always use the same title. If <a href="http://drupal.org/project/token">token module</a> is installed, the static title value may use any other node field as its value. Static and token-based titles may include most inline XHTML tags such as <em>strong</em>, <em>em</em>, <em>img</em>, <em>span</em>, etc.'),
);
$form['title_value'] = array(
'#type' => 'textfield',
'#default_value' => $field['title_value'],
'#size' => '46',
);
if (module_exists('token')) {
$form['tokens'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Placeholder tokens'),
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
);
$form['tokens']['help'] = array(
'#value' => theme('token_help', 'node'),
);
$form['enable_tokens'] = array(
'#type' => 'checkbox',
'#title' => t('Allow user-entered tokens'),
'#default_value' => isset($field['enable_tokens']) ? $field['enable_tokens'] : 1,
'#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'),
);
}
$form['display'] = array(
'#tree' => TRUE,
);
$form['attributes'] = array(
'#tree' => TRUE,
);
$form['attributes']['width'] = array(
'#type' => 'textfield',
'#title' => t('width of the iframe'),
'#description' => t('iframes need fix width and height, only numbers are allowed.'),
'#default_value' => empty($field['attributes']['width']) ? '100%' : $field['attributes']['width'],
'#maxlength' => 4,
'#size' => 4,
);
$form['attributes']['height'] = array(
'#type' => 'textfield',
'#title' => t('height of the iframe'),
'#description' => t('iframes need fix width and height, only numbers are allowed.'),
'#default_value' => empty($field['attributes']['height']) ? '700' : $field['attributes']['height'],
'#maxlength' => 4,
'#size' => 4,
);
$form['attributes']['frameborder'] = array(
'#type' => 'select',
'#title' => t('Frameborder'),
'#options' => array(
'0' => t('no frameborder'),
'yes' => t('show frameborder'),
),
'#default_value' => empty($field['attributes']['frameborder']) ? '0' : $field['attributes']['frameborder'],
'#description' => t('Frameborder is the border arround the iframe. Mostly people want it silent, so the default value for frameborder is 0 = no.'),
);
$form['attributes']['scrolling'] = array(
'#type' => 'select',
'#title' => t('Scrolling'),
'#options' => array(
'auto' => t('Scrolling automatic'),
'no' => t('Scrolling disabled'),
'yes' => t('Scrolling enabled'),
),
'#default_value' => empty($field['attributes']['scrolling']) ? 'auto' : $field['attributes']['scrolling'],
'#description' => t('Scrollbars help the user to reach all iframe content despite the real height of the iframe content. Please disable it only if You know what You are doing.'),
);
$form['attributes']['transparency'] = array(
'#type' => 'select',
'#title' => t('Transparency'),
'#options' => array(
'0' => t('no transparency'),
'yes' => t('allow transparency'),
),
'#default_value' => empty($field['attributes']['transparency']) ? '0' : $field['attributes']['transparency'],
'#description' => t('Allow transparency per CSS in the outer iframe tag. You have to set background-color:transparent in Your IFrame too for the body tag!'),
);
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
'#description' => t('Adds this class-definition to the iframe. Multiple classes should be separated by spaces. You can use a class "autoresize" if You want height-autoresizing for iframes of the same domain.'),
'#default_value' => empty($field['attributes']['class']) ? '' : $field['attributes']['class'],
);
return $form;
case 'validate':
if ($field['title'] == 'value' && empty($field['title_value'])) {
form_set_error('title_value', t('A default title must be provided if the title is a static value'));
}
if (empty($field['attributes']['width']) || (int) $field['attributes']['width'] < 1) {
form_set_error('width_value', t('A default width and height must be provided.'));
}
if (empty($field['attributes']['height']) || (int) $field['attributes']['height'] < 1) {
form_set_error('height_value', t('A default width and height must be provided.'));
}
break;
case 'save':
return array(
'attributes',
'display',
'url',
'title',
'title_value',
'enable_tokens',
);
case 'database columns':
return array(
'url' => array(
'type' => 'varchar',
'length' => 1024,
'not null' => FALSE,
'sortable' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE,
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE,
),
);
}
}
function theme_iframe_field_settings($form) {
dmsg(3, 'func theme_iframe_field_settings');
$title_value = drupal_render($form['title_value']);
$title_checkbox = drupal_render($form['title']['value']);
$form['title']['value'] = array(
'#value' => '<div class="container-inline">' . $title_checkbox . $title_value . '</div>',
);
return drupal_render($form);
}
function iframe_content_is_empty($item, $field) {
dmsg(3, 'func iframe_content_is_empty');
if (empty($item['url'])) {
return TRUE;
}
return FALSE;
}
function iframe_field($op, &$node, $field, &$items, $teaser, $page) {
dmsg(3, 'func iframe_field op=' . $op . ' field=' . $field);
switch ($op) {
case 'load':
foreach ($items as $delta => $item) {
_iframe_load($items[$delta], $delta);
}
break;
case 'validate':
$optional_field_found = FALSE;
foreach ($items as $delta => $value) {
_iframe_validate($items[$delta], $delta, $field, $node, $optional_field_found);
}
if ($field['url'] == 'optional' && $field['title'] == 'optional' && $field['required'] && !$optional_field_found) {
form_set_error($field['field_name'] . '][0][title', t('At least one title or URL must be entered.'));
}
break;
case 'presave':
foreach ($items as $delta => $value) {
_iframe_process($items[$delta], $delta, $field, $node);
}
break;
case 'sanitize':
foreach ($items as $delta => $value) {
_iframe_sanitize($items[$delta], $delta, $field, $node);
}
break;
}
}
function iframe_widget_info() {
dmsg(3, 'func iframe_widget_info');
return array(
'iframe' => array(
'label' => 'Text Fields for Title and IFrame-url',
'field types' => array(
'iframe',
),
'multiple values' => CONTENT_HANDLE_CORE,
),
);
}
function iframe_widget(&$form, &$form_state, $field, $items, $delta = 0) {
dmsg(3, 'func iframe_widget');
$element = array(
'#type' => $field['widget']['type'],
'#default_value' => isset($items[$delta]) ? $items[$delta] : '',
'#title' => $field['widget']['label'],
'#weight' => $field['widget']['weight'],
'#description' => $field['widget']['description'],
'#required' => $field['required'],
'#field' => $field,
);
return $element;
}
function _iframe_load(&$item, $delta = 0) {
dmsg(3, 'func _iframe_load');
if (!is_array($item['attributes'])) {
$item['attributes'] = unserialize($item['attributes']);
}
}
function _iframe_process(&$item, $delta = 0, $field, $node) {
dmsg(3, 'func _iframe_process');
$item['url'] = trim($item['url']);
$item['attributes']['width'] = iframe_validate_size($item['attributes']['width'], $field['widget']['default_value'][$delta]['width']);
$item['attributes']['height'] = iframe_validate_size($item['attributes']['height'], $field['widget']['default_value'][$delta]['height']);
$item['attributes'] = serialize($item['attributes']);
if (isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'] && is_object($node)) {
if (!iframe_validate_url($item['url'])) {
unset($item['url']);
}
}
}
function _iframe_validate(&$item, $delta, $field, $node, &$optional_field_found) {
dmsg(3, 'func _iframe_validate');
$trimmed_title = trim($item['title']);
$trimmed_url = trim($item['url']);
if ($item['url'] && !(isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'] && !$field['required'])) {
if (iframe_validate_url($trimmed_url) == FALSE) {
form_set_error($field['field_name'] . '][' . $delta . '][url', t('Not a valid iframe-url.'));
}
if ($field['title'] == 'required' && empty($trimmed_title)) {
form_set_error($field['field_name'] . '][' . $delta . '][title', t('Titles are required for all iframes.'));
}
}
if ($field['url'] !== 'optional' && drupal_strlen($item['title']) > 0 && empty($trimmed_url)) {
form_set_error($field['field_name'] . '][' . $delta . '][url', t('You cannot enter a title without a iframe url.'));
}
if ($field['url'] == 'optional' && $field['title'] == 'optional' && (!empty($trimmed_title) || !empty($trimmed_url))) {
$optional_field_found = TRUE;
}
}
function _iframe_sanitize(&$item, $delta, &$field, &$node) {
static $iframe_count = 0;
dmsg(3, 'func _iframe_sanitize');
if (empty($item['url']) && empty($item['title'])) {
return;
}
if (module_exists('token') && $field['enable_tokens']) {
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$item['url'] = token_replace($item['url'], 'node', $token_node);
}
$type = iframe_validate_url($item['url']);
$url = iframe_cleanup_url($item['url']);
if (strpos($url, '#') !== FALSE) {
$item['fragment'] = drupal_substr($url, strpos($url, '#') + 1);
$url = drupal_substr($url, 0, strpos($url, '#'));
}
if (strpos($url, '?') !== FALSE) {
$item['query'] = drupal_substr($url, strpos($url, '?') + 1);
$url = drupal_substr($url, 0, strpos($url, '?'));
}
$item['url'] = $url;
$display_url = $type == iframe_EMAIL ? str_replace('mailto:', '', $url) : url($url, array(
'query' => isset($item['query']) ? $item['query'] : NULL,
'fragment' => isset($item['fragment']) ? $item['fragment'] : NULL,
'absolute' => TRUE,
));
if (drupal_strlen($display_url) > 72) {
$display_url = drupal_substr($display_url, 0, 72) . "...";
}
$item['display_url'] = $display_url;
if ($field['title'] == 'value' && drupal_strlen(trim($field['title_value']))) {
$title = $field['title_value'];
}
else {
$title = $item['title'];
}
if (module_exists('token') && ($field['title'] == 'value' || $field['enable_tokens'])) {
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$title = filter_xss(token_replace($title, 'node', $token_node), array(
'b',
'br',
'code',
'em',
'i',
'img',
'span',
'strong',
'sub',
'sup',
'tt',
'u',
));
$item['html'] = TRUE;
}
$item['display_title'] = empty($title) ? '' : $title;
_iframe_load($item);
$attributes = array();
if (!empty($item['attributes']) && is_array($item['attributes'])) {
foreach ($item['attributes'] as $attribute => $attbvalue) {
if (isset($attbvalue) && ($field['attributes'][$attribute] == 'user' || $attribute == 'width' || $attribute == 'class' || $attribute == 'height' || $attribute == 'frameborder' || $attribute == 'scrolling' || $attribute == 'transparency')) {
$attributes[$attribute] = $attbvalue;
}
}
}
if (is_array($field['attributes'])) {
foreach ($field['attributes'] as $attribute => $attbvalue) {
if (!empty($attbvalue) && $attbvalue != 'default' && $attbvalue != 'user' && !isset($attributes[$attribute])) {
$attributes[$attribute] = $attbvalue;
}
}
}
if ($type != iframe_EXTERNAL && isset($attributes['rel']) && strpos($attributes['rel'], 'nofollow') !== FALSE) {
$attributes['rel'] = str_replace('nofollow', '', $attributes['rel']);
if (empty($attributes['rel'])) {
unset($attributes['rel']);
}
}
$item['attributes'] = $attributes;
$item['label'] = $field['widget']['label'];
$item['html-id'] = 'iframe-' . $iframe_count;
$iframe_count++;
if (!isset($item['attributes']['class'])) {
$item['attributes']['class'] = '';
}
$item['attributes']['class'] .= ' iframe-delta-' . $delta;
}
function iframe_theme() {
dmsg(3, 'func iframe_theme');
return array(
'iframe_field_settings' => array(
'arguments' => array(
'element' => NULL,
),
),
'iframe_formatter_default' => array(
'arguments' => array(
'element' => NULL,
),
),
'iframe_formatter_iframeonly' => array(
'arguments' => array(
'element' => NULL,
),
),
'iframe_formatter_asurl' => array(
'arguments' => array(
'element' => NULL,
),
),
'iframe_formatter_asurl_withuri' => array(
'arguments' => array(
'element' => NULL,
),
),
'iframe' => array(
'arguments' => array(
'element' => NULL,
),
),
);
}
function theme_iframe($element) {
dmsg(3, 'func theme_iframe');
drupal_add_css(drupal_get_path('module', 'iframe') . '/iframe.css');
if (empty($element['#field']['multiple'])) {
if (isset($element['url']) && isset($element['title'])) {
$element['url']['#title'] = $element['#title'] . ' ' . $element['url']['#title'];
$element['title']['#title'] = $element['#title'] . ' ' . $element['title']['#title'];
}
elseif ($element['url']) {
$element['url']['#title'] = $element['#title'];
}
}
$output = '';
$output .= '<div class="iframe-field-subrow clear-block">';
if (isset($element['title'])) {
$output .= '<div class="iframe-field-title iframe-field-column">' . theme('textfield', $element['title']) . '</div>';
}
$output .= '<div class="iframe-field-url' . (isset($element['title']) ? ' iframe-field-column' : '') . '">' . theme('textfield', $element['url']) . '</div>';
$output .= '<div>' . t('Width and Height of the IFrame') . '</div>';
if (!empty($element['attributes'])) {
foreach ($element['attributes'] as $key => $attr) {
if (!isset($attr['#type'])) {
continue;
}
$value = isset($attr['#value']) ? $attr['#value'] : '';
$output .= '<div class="iframe-attributes iframe-field-column">' . theme($attr['#type'], $attr, $value) . '</div>';
}
}
$output .= '</div>';
return $output;
}
function iframe_elements() {
dmsg(3, 'func iframe_elements');
$elements = array();
$elements['iframe'] = array(
'#input' => TRUE,
'#columns' => array(
'url',
'title',
),
'#process' => array(
'iframe_process',
),
);
return $elements;
}
function iframe_process($element, $edit, $form_state, $form) {
dmsg(3, 'func iframe_process');
$field = $form['#field_info'][$element['#field_name']];
$delta = $element['#delta'];
_iframe_load($element['#value']);
dmsg(4, 'func iframe_process after _iframe_load');
$element['url'] = array(
'#type' => 'textfield',
'#maxlength' => '1024',
'#title' => t('URL'),
'#description' => $element['#description'],
'#required' => $delta == 0 && $field['url'] !== 'optional' ? $element['#required'] : FALSE,
'#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
);
if ($field['title'] != 'none' && $field['title'] != 'value') {
$element['title'] = array(
'#type' => 'textfield',
'#maxlength' => '255',
'#title' => t('Title'),
'#required' => $delta == 0 && $field['title'] == 'required' ? $field['required'] : FALSE,
'#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
);
}
$element['attributes']['width'] = array(
'#type' => 'textfield',
'#maxlength' => '4',
'#size' => '4',
'#title' => t('Width'),
'#required' => $delta == 0 && $field['width'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['width']) ? $element['#value']['attributes']['width'] : $field['attributes']['width'],
);
$element['attributes']['height'] = array(
'#type' => 'textfield',
'#maxlength' => '4',
'#size' => '4',
'#title' => t('Height'),
'#required' => $delta == 0 && $field['height'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['height']) ? $element['#value']['attributes']['height'] : $field['attributes']['height'],
);
$element['attributes']['frameborder'] = array(
'#type' => 'select',
'#title' => t('Frameborder'),
'#options' => array(
'0' => t('no frameborder'),
'yes' => t('show frameborder'),
),
'#description' => t('Frameborder is the border arround the iframe. Mostly people want it silent, so the default value for frameborder is 0.'),
'#required' => $delta == 0 && $field['frameborder'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['frameborder']) ? $element['#value']['attributes']['frameborder'] : $field['attributes']['frameborder'],
);
$element['attributes']['scrolling'] = array(
'#type' => 'select',
'#title' => t('Scrolling'),
'#options' => array(
'auto' => t('Scrolling automatic'),
'no' => t('Scrolling disabled'),
'yes' => t('Scrolling enabled'),
),
'#description' => t('Scrollbars help the user to reach all iframe content despite the real height of the iframe content. Please disable it only if You know what You are doing.'),
'#required' => $delta == 0 && $field['scrolling'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['scrolling']) ? $element['#value']['attributes']['scrolling'] : $field['attributes']['scrolling'],
);
$element['attributes']['transparency'] = array(
'#type' => 'select',
'#title' => t('Transparency'),
'#options' => array(
'0' => t('no transparency'),
'yes' => t('allow transparency'),
),
'#description' => t('Allow transparency per CSS in the outer iframe tag. You have to set background-color:transparent in Your IFrame too for the body tag!'),
'#required' => $delta == 0 && $field['transparency'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['transparency']) ? $element['#value']['attributes']['transparency'] : $field['attributes']['transparency'],
);
$element['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
'#description' => t('When output, this iframe will have this class attribute. Multiple classes should be separated by spaces. In future versions You can use a class "autoresize" if You want autoresizing the height for iframes which originates from the same domain.'),
'#required' => $delta == 0 && $field['class'] == 'required' ? $field['required'] : FALSE,
'#default_value' => !empty($element['#value']['attributes']['class']) ? $element['#value']['attributes']['class'] : $field['attributes']['class'],
);
return $element;
}
function iframe_field_formatter_info() {
dmsg(3, 'func iframe_field_formatter_info');
return array(
'default' => array(
'label' => t('Title, over iframe (default)'),
'field types' => array(
'iframe',
),
'multiple values' => CONTENT_HANDLE_CORE,
),
'iframeonly' => array(
'label' => t('IFrame without title'),
'field types' => array(
'iframe',
),
'multiple values' => CONTENT_HANDLE_CORE,
),
'asurl' => array(
'label' => t('A link with the given title'),
'field types' => array(
'iframe',
),
'multiple values' => CONTENT_HANDLE_CORE,
),
'asurl_withuri' => array(
'label' => t('A link with the iframe uri'),
'field types' => array(
'iframe',
),
'multiple values' => CONTENT_HANDLE_CORE,
),
);
}
function theme_iframe_formatter_default($element) {
dmsg(3, 'func theme_iframe_formatter_default');
if (empty($element['#item']['url'])) {
return '';
}
return iframe_iframe($element['#item']['display_title'], $element['#item']['url'], $element['#item']);
}
function theme_iframe_formatter_iframeonly($element) {
dmsg(3, 'func theme_iframe_formatter_iframeonly');
if (empty($element['#item']['url'])) {
return '';
}
return iframe_iframe('', $element['#item']['url'], $element['#item']);
}
function theme_iframe_formatter_asurl($element) {
dmsg(3, 'func theme_iframe_formatter_asurl');
if (empty($element['#item']['url'])) {
return '';
}
$linktext = empty($element['#item']['display_title']) ? $element['#item']['url'] : $element['#item']['display_title'];
return l($linktext, $element['#item']['url'], $element['#item']);
}
function theme_iframe_formatter_asurl_withuri($element) {
dmsg(3, 'func theme_iframe_formatter_asurl_withuri');
if (empty($element['#item']['url'])) {
return '';
}
$linktext = $element['#item']['url'];
return l($linktext, $element['#item']['url'], $element['#item']);
}
function iframe_token_list($type = 'all') {
dmsg(3, 'func iframe_token_list');
if ($type == 'field' || $type == 'all') {
$tokens = array();
$tokens['iframe']['url'] = t("iframe URL");
$tokens['iframe']['title'] = t("iframe title");
$tokens['iframe']['view'] = t("Formatted html iframe");
return $tokens;
}
}
function iframe_token_values($type, $object = NULL) {
dmsg(3, 'func iframe_token_values');
if ($type == 'field') {
$item = $object[0];
$tokens['url'] = $item['url'];
$tokens['title'] = $item['title'];
$tokens['view'] = isset($item['view']) ? $item['view'] : '';
return $tokens;
}
}
function iframe_cleanup_url($url, $protocol = "http") {
dmsg(3, 'func iframe_cleanup_url');
$url = trim($url);
$type = iframe_validate_url($url);
if ($type == iframe_EXTERNAL) {
$protocol_match = preg_match("/^([a-z0-9][a-z0-9\\.\\-_äöü]*:\\/\\/)/i", $url);
if (empty($protocol_match)) {
$domain_match = preg_match('/^(([a-z0-9]([a-z0-9\\-_äöü]*\\.)+)(' . iframe_DOMAINS . '|[a-z]{2}))/i', $url);
if (!empty($domain_match)) {
$url = $protocol . '://' . $url;
}
}
}
return $url;
}
function iframe_validate_url($text) {
dmsg(3, 'func iframe_validate_url');
$allowed_protocols = variable_get('filter_allowed_protocols', array(
'http',
'https',
'ftp',
'news',
'nntp',
'telnet',
'mailto',
'irc',
'ssh',
'sftp',
'webcal',
));
$protocol = '((' . implode("|", $allowed_protocols) . '):\\/\\/)';
$authentication = '([a-z0-9]+(:[a-z0-9]+)?@)';
$domain = '(([a-z0-9]([a-z0-9\\-_\\[\\]äöü])*)(\\.(([a-z0-9\\-_\\[\\]äöü])+\\.)*(' . iframe_DOMAINS . '|[a-z]{2}))?)';
$ipv4 = '([0-9]{1,3}(\\.[0-9]{1,3}){3})';
$ipv6 = '([0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})';
$port = '(:([0-9]{1,5}))';
$external_pattern = '/^' . $protocol . '?' . $authentication . '?' . '(' . $domain . '|' . $ipv4 . '|' . $ipv6 . ' |localhost)' . $port . '?';
$internal_pattern = "/^([a-z0-9_\\-+\\[\\]]+)";
$directories = "(\\/[a-z0-9_\\-\\.~+%=&,\$'():;*@\\[\\]]*)*";
$query = "(\\/?\\?([?a-z0-9+_|\\-\\.\\!\\/\\\\%=&,\$'():;*@\\[\\]\\{\\}]*))";
$anchor = "(#[a-z0-9_\\-\\.~+%=&,\$'():;*@\\[\\]]*)";
$end = $directories . '?' . $query . '?' . $anchor . '?' . '$/i';
$user = '[a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~\'\\[\\]]+';
$email_pattern = '/^mailto:' . $user . '@' . '(' . $domain . '|' . $ipv4 . '|' . $ipv6 . '|localhost)' . $query . '?$/';
if (strpos($text, '<front>') === 0) {
return iframe_FRONT;
}
if (in_array('mailto', $allowed_protocols) && preg_match($email_pattern, $text)) {
return iframe_EMAIL;
}
if (preg_match($internal_pattern . $end, $text)) {
return iframe_INTERNAL;
}
if (preg_match($external_pattern . $end, $text)) {
return iframe_EXTERNAL;
}
return FALSE;
}
function iframe_validate_size($size, $default = "100") {
dmsg(3, 'func iframe_validate_size (size=' . $size . ', default=' . $default);
if (is_numeric($size)) {
return $size > 0 ? $size : $default;
}
if (preg_match('/^\\d+\\%$/', $size)) {
return $size;
}
return $default;
}
function iframe_iframe($text, $path, $options = FALSE) {
dmsg(3, 'func iframe_iframe');
if (!$options) {
$options = array();
}
$options += array(
'attributes' => array(),
'html' => FALSE,
);
if (!isset($options['attributes']['width'])) {
$options['attributes']['width'] = '100%';
}
if (!isset($options['attributes']['height'])) {
$options['attributes']['height'] = '701';
}
if (!isset($options['attributes']['frameborder']) || empty($options['attributes']['frameborder'])) {
$options['attributes']['frameborder'] = '0';
}
if (!isset($options['attributes']['scrolling']) || empty($options['attributes']['scrolling'])) {
$options['attributes']['scrolling'] = 'auto';
}
if (!isset($options['attributes']['transparency']) || empty($options['attributes']['transparency'])) {
$options['attributes']['transparency'] = '0';
}
$htmlid = '';
if (isset($options['html-id']) && !empty($options['html-id'])) {
$htmlid = ' id="' . $options['html-id'] . '" name="' . $options['html-id'] . '"';
}
if ($path == $_GET['q'] || $path == '<front>' && drupal_is_front_page()) {
if (isset($options['attributes']['class'])) {
$options['attributes']['class'] .= ' active';
}
else {
$options['attributes']['class'] = 'active';
}
}
if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {
$options['attributes']['title'] = strip_tags($options['attributes']['title']);
}
$options_link = array();
$options_link['attributes'] = array();
$options_link['attributes']['title'] = $options['attributes']['title'];
include_once drupal_get_path('module', 'content') . '/includes/content.crud.inc';
return (empty($text) ? '' : '<div class="iframe_title">' . ($options['html'] ? $text : check_plain($text)) . '</div>') . '<iframe src="' . check_url(url($path, $options)) . '"' . drupal_attributes($options['attributes']) . $htmlid . '>' . t('Your browser does not support iframes. But You can use the following link.') . ' ' . l('Link', url($path, $options), $options_link) . '</iframe>';
}