Index: views-view-row-unformatted.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views-view-row-unformatted.tpl.php,v retrieving revision 1.1 diff -u -r1.1 views-view-row-unformatted.tpl.php --- views-view-row-unformatted.tpl.php 25 May 2008 05:54:02 -0000 1.1 +++ views-view-row-unformatted.tpl.php 13 Apr 2009 18:40:27 -0000 @@ -1,5 +1,5 @@ $field) // print $id.":".$field->content."\n"; -$field_separator = filter_xss_admin($options['separator']); -foreach($row as $field_label => $field_value) - $row_unformatted.= $field_label.":".(!is_null($field_value) ? $field_value: "").$field_separator; +$field_separator = filter_xss($options['separator']); +foreach($row as $field_label => $field_value) { + $label = str_replace(':', '#colon#', $field_label); + $value = filter_xss(str_replace(':', '#colon#', $field_value)); + $row_unformatted.= $label.":".(!is_null($value) ? $value : "").$field_separator; +} print rtrim($row_unformatted, $field_separator).PHP_EOL; \ No newline at end of file Index: views-view-json.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views-view-json.tpl.php,v retrieving revision 1.2 diff -u -r1.2 views-view-json.tpl.php --- views-view-json.tpl.php 25 May 2008 09:04:45 -0000 1.2 +++ views-view-json.tpl.php 13 Apr 2009 18:40:27 -0000 @@ -1,8 +1,8 @@ style_plugin->row_plugin) !== 'unformatted_plugin_row') { + print ('The row plugin is not of type Unformatted.'); + return; +} +else if (($view->style_plugin->row_plugin->options['separator']) !== '|') { + print ('The row plugin separator is not "|" (you can set this in the options for the row style plugin.)'); + return; +} $items = array(); foreach($rows as $row) { -// print_r($row).EOL; $items[] = explode("|", trim($row)); - -} -//print_r($items); -//foreach ($items as $item) { -// print_r($item).PHP_EOL; -// foreach($item as $itemfield) { -// print($itemfield); -// $itemfieldarray = explode(":", $itemfield); -// print_r($itemfieldarray).PHP_EOL; -// $label = $itemfieldarray[0]; $value=$itemfieldarray[1]; -// print $label." : ".$value; -// } -//} + } + +if ($options['format'] == 'Simple') json_simple_render($items, $view); +if ($options['format'] == 'Exhibit') json_exhibit_render($items, $view); -if ($options['format'] == 'Exhibit') json_exhibit_render($items); +function json_simple_render($items, $view) { + define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S'); + $json = '"nodes":'.str_repeat(" ", 4)."[\n"; + foreach($items as $item) { + $json.= str_repeat(" ", 6)."{\n"; + foreach($item as $itemfield) { + $itemfieldarray = explode(":", $itemfield); + + /*replace escaped colons with actual colon*/ + $itemfieldarray[0] = str_replace('#colon#', ':', $itemfieldarray[0]); + $itemfieldarray[1] = str_replace('#colon#', ':', $itemfieldarray[1]); + + $label = trim(views_json_strip_illegal_chars(views_json_encode_special_chars($itemfieldarray[0]))); + $value = views_json_encode_special_chars(trim(views_json_is_date($itemfieldarray[1]))); + if (strtotime($value)) + $value = gmstrftime(EXHIBIT_DATE_FORMAT, strtotime($value)); + $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields + $json.=str_repeat(" ", 8).'"'.$label.'"'. " ".": ".'"'.$value.'"'.",\n"; + } + $json.=str_repeat(" ", 6)."},\n\n"; + } + $json.=str_repeat(" ", 4)."]"; + /* + * The following will cause an error in a live view preview - comment out if + * debugging in there. + */ + if ($view->override_path) { //inside a live preview so just output the text (not working yet) + print $json; + } + else { //real deal so switch the content type and stop further processing of the page + drupal_set_header('Content-Type: text/javascript'); + print $json; + module_invoke_all('exit'); + exit; + } + +} -function json_exhibit_render($items) { +function json_exhibit_render($items, $view) { define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S'); - $json = "{\n".str_repeat(" ", 4).'"items"'." : ". " ["; - foreach ($items as $item) { - $json.="\n".str_repeat(" ", 8)."{\n"; + $json = "{\n".str_repeat(" ", 4).'"items"'." : ". "[\n"; + foreach ($items as $item) { + $json.=str_repeat(" ", 8)."{\n"; + $json.=str_repeat(" ", 12).'"type" '. " ".": ".'"'.'##type##'.'",'."\n"; + $json.=str_repeat(" ", 12).'"label" '. " "." : ".'"'.'##label##'.'",'."\n"; foreach ($item as $itemfield) { $itemfieldarray = explode(":", $itemfield); - $label = $itemfieldarray[0]; $value=$itemfieldarray[1]; - $value = preg_replace('/<.*?>/', '', $value); // strip html tags - $value = str_replace(array("\r", "\n", ','), ' ', $value); // strip line breaks and commas - $value = str_replace('"', '""', $value); // escape " characters - $value = decode_entities($value); - $json.=str_repeat(" ", 8).$label. " ".": ".'"'.$value.'"'."\n"; + + /*replace escaped colons with actual colon*/ + $itemfieldarray[0] = str_replace('#colon#', ':', $itemfieldarray[0]); + $itemfieldarray[1] = str_replace('#colon#', ':', $itemfieldarray[1]); + + $label = trim(views_json_strip_illegal_chars(views_json_encode_special_chars($itemfieldarray[0]))); + $value=views_json_encode_special_chars(trim(views_json_is_date($itemfieldarray[1]))); + //if (empty($value)) continue; + if (strtotime($value)) + $value = gmstrftime(EXHIBIT_DATE_FORMAT, strtotime($value)); + $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields + if ($label == 'type') $json = str_replace('##type##', $value, $json); + elseif ($label == 'label') $json = str_replace('##label##', $value, $json); + else $json.=str_repeat(" ", 12).'"'.$label.'"'. " ".": ".'"'.$value.'"'.",\n"; } - $json.=str_repeat(" ", 8)."},\n"; + if (strpos($json, '##type##') !== false) + $json = str_replace('##type##', 'Item', $json); + if (strpos($json, '##label##') !== false) + $json = str_replace('##label##', 'none', $json); + $json = rtrim($json, ",\n"); + $json.="\n"; + $json.=str_repeat(" ", 8)."},\n"; } + $json = rtrim($json, ",\n"); + $json.="\n"; $json.=str_repeat(" ", 4)."]\n}"; /* * The following will cause an error in a live view preview - comment out if * debugging in there. */ - drupal_set_header('Content-Type: text/javascript'); - print $json; - module_invoke_all('exit'); - exit; + if ($view->override_path) { //inside a live preview so just output the text + print $json; + } + else { //real deal so switch the content type and stop further processing of the page + drupal_set_header('Content-Type: text/javascript'); + print $json; + module_invoke_all('exit'); + exit; + } + } Index: views_json.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views_json.info,v retrieving revision 1.1 diff -u -r1.1 views_json.info --- views_json.info 25 May 2008 05:54:02 -0000 1.1 +++ views_json.info 13 Apr 2009 18:40:27 -0000 @@ -1,6 +1,6 @@ -; $Id $ name = Views JSON -description = "Views style plugin to render node content as JSON" -package = Views +description = "Views style plugin to render node content as JSON." +package = Views Datasource +dependencies[] = views_datasource core = 6.x -dependencies[] = views \ No newline at end of file + Index: views_json.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views_json.views.inc,v retrieving revision 1.1 diff -u -r1.1 views_json.views.inc --- views_json.views.inc 25 May 2008 05:54:02 -0000 1.1 +++ views_json.views.inc 13 Apr 2009 18:40:27 -0000 @@ -1,5 +1,5 @@ t('JSON data document'), 'theme' => 'views_view_json', 'help' => t('Displays nodes in the JSON data format.'), - 'handler' => 'views_plugin_style_json', + 'handler' => 'json_plugin_style', 'uses row plugin' => TRUE, 'uses fields' => TRUE, 'uses options' => TRUE, 'type' => 'normal', ), - ), - 'row' => array( //declare the unformatted row plugin - 'unformatted' => array( - 'title' => t('Unformatted'), - 'help' => t('(Displays the unformatted data for each row from the views query with each row on a new line. Set as | for views_json.'), - 'handler' => 'views_plugin_row_unformatted', - 'theme' => 'views_view_row_unformatted', - 'uses fields' => TRUE, - 'uses options' => TRUE, - 'type' => 'normal', - ) - ) + ) ); } /** - * Implementation of views_plugin_style - * - */ - -class views_plugin_style_json extends views_plugin_style { - - /** - * Set default options - */ - function options(&$options) { - $options['format'] = 'Exhibit'; - } - - /** - * Provide a form for setting options. - * - * @param array $form - * @param array $form_state - */ - function options_form(&$form, &$form_state) { - $form['format'] = array( - '#type' => 'radios', - '#title' => t('JSON data format'), - '#options' => array('Exhibit' => t('MIT Simile/Exhibit'), 'Canonical' => t('Canonical'), 'JSONP' => t('JSONP')), - '#default_value' => $this->options['format'], - ); - } - -} - -/** * Theme preprocess function for views-view-json.tpl.php * * @param array $vars @@ -80,73 +38,3 @@ $options = $view->style_handler->options; $handler = $view->style_handler; } - - -/** - * Implementation of views_row_plugin - * - */ -class views_plugin_row_unformatted extends views_plugin_row { - - /** - * Set default options - * - * @param array $options - */ - function options(&$options) { - $options['separator'] = '|'; - } - - /** - * Provide a form for setting options. - */ - function options_form(&$form, &$form_state) { - $fields = $this->display->handler->get_option('fields'); - $options = array(); - foreach ($fields as $field => $info) { - $handler = views_get_handler($info['table'], $info['field'], 'field'); - if ($handler) { - $options[$field] = $handler->ui_name(); - } - } - - $form['separator'] = array( - '#title' => t('Separator'), - '#type' => 'textfield', - '#size' => 10, - '#default_value' => isset($this->options['separator']) ? $this->options['separator'] : ',', - '#description' => t('The separator is placed between fields.'), - ); - } - -} - -/** - * Theme preprocess function for views-view-row-unformatted.tpl.php - */ -function template_preprocess_views_view_row_unformatted(&$vars) { - $view = $vars['view']; - //print('preprocess'); - // Loop through the fields for this view. - foreach ($view->field as $id => $field) { - if (!empty($field['handler']) && is_object($field['handler'])) { - $object = new stdClass(); - $object->content = $field['handler']->theme($vars['row']); - if (isset($field['handler']->field_alias) && isset($vars['row']->{$field['handler']->field_alias})) { - $object->raw = $vars['row']->{$field['handler']->field_alias}; - } - else { - $object->raw = NULL; // make sure it exists to reduce NOTICE - } - if (!empty($vars['options']['separator']) && $object->content) { - $object->separator = filter_xss_admin($vars['options']['separator']); - } - - $object->handler = $field['handler']; - $object->class = views_css_safe($id); - $object->label = check_plain($field['handler']->label()); - $vars['fields'][$id] = $object; - } - } - -} Index: views_json.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views_json.module,v retrieving revision 1.1 diff -u -r1.1 views_json.module --- views_json.module 25 May 2008 05:54:02 -0000 1.1 +++ views_json.module 13 Apr 2009 18:40:27 -0000 @@ -1,13 +1,69 @@ 2, + ); +} + +/** + * Strips illegal JSON characters in identifier string + * + * @param string $input + * @return string + */ + +function views_json_strip_illegal_chars($input) { + $output = str_replace(array('{','}','[', ']', ':', ',', '"', "'", chr(47), chr(92)), '', $input); + $output = preg_replace( + '/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP + '\x{01}-\x{1F}'. //Non-printable ASCII characters + '\x{0}]/u', // NULL byte + '', $output); + + return $output; +} + +/** + * Encodes special JSON characters in string + * + * @param string $input + * @return string + */ +function views_json_encode_special_chars($input) { + $output = str_replace(chr(92), '\\', $input); + $output = str_replace(chr(47), '\/', $output); + $output = str_replace('"', '\"', $output); + $output = str_replace(chr(8), '\b', $output); + $output = str_replace(chr(12), '\f', $output); + $output = str_replace(chr(13).chr(10), '\n', $output); + $output = str_replace(chr(10), '\n', $output); + $output = str_replace(chr(13), '\r', $output); + $output = str_replace(chr(9), '\t', $output); + return $output; +} + +/** + * If input is a serialized date array, return a date string + * + * @param unknown_type $input + * @return unknown + */ +function views_json_is_date ($input) { + if (strpos($input, 'a:3:{s:5:"month"') !== 0) return $input; + else { //serialized date array + $date = unserialize($input); + return date(DATE_ISO8601, mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); + } +} \ No newline at end of file Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/README.txt,v retrieving revision 1.1 diff -u -r1.1 README.txt --- README.txt 25 May 2008 05:54:02 -0000 1.1 +++ README.txt 13 Apr 2009 18:40:27 -0000 @@ -1,21 +1,43 @@ -$Id: README.txt,v 1.1 2008/05/25 05:54:02 allisterbeharry Exp $ +$Id: README.txt,v 1.1.2.3 2008/07/09 06:47:58 allisterbeharry Exp $ Views Datasource README --------------------------------------- Current Version --------------- -6.x-0.1-dev +6.x-1.0-ALPHA2 Release Notes ------------- -CVS module created and intial code uploaded to repository. This is a -proof-of-concept release with a working views_json plugin for Drupal 6. In the -Views interface simply select the view style as JSON data document (Exhibit -format only) and the row style as Unformatted (separator must be |). Because the -template changes the page Content-type to text/javascript and immediately exits -Drupal, the live preview will throw an error. This can be ignored; just save -your view as a page and view it normally at the URL to get the JSON output. +Exhibit JSON output now validates with the validator at +http://simile.mit.edu/babel/validator Added simple JSON support to views_json +Added views_xml plugin with raw XML and OPML renderer. Added views_rdf plugin +with FOAF renderer. Added views_xhtml plugin with hCard renderer. + +views_json and views_xml will take the nodes generated by a view and output +them as, in the case of views_json, an array of Javascript objects with each +object's properties corresponding to a view field, and in the case of views_xml, +an XML document with the root element called 'nodes' and a 'node' element with +each node's sub-elements corresponding to a view field. views_rdf will render +the nodes generated by a view as an RDF/XML FOAF document with each + element corresponding to a node in the view. To use just have +fields in the view named as their equivalent FOAF properties - for example to +have a or element, have a field named 'name' and 'nick' +in your view. Similarly views_xhtml provides the hCard plugin which will render +each node in the XHTML hCard format - just have fields corresponding to hCard +properties defined in the view. For example to create an element inside +the
root element, just have one or more fields in the view +containing the text 'email'. + +The FOAF and vCard renderers are most useful with view based on user profiles +where you can create profile fields corresponding to properties defined in the +FOAF (http://xmlns.com/foaf/spec/) or hCard +(http://microformats.org/wiki/hcard-cheatsheet) spec. However any node type +(like those created with nodeprofile or Bio or Advanced Profile or Content +Profile) can be used in the view. It doesn't matter what data table the view +is base on, only what fields are exposed. See http://soc2008.hotdrupal.com for +ways to use the plugins, and http://groups.drupal.org/node/11387 for more +docs. About ----- @@ -33,4 +55,15 @@ 1)views_xml - Output as raw XML, OPML, and Atom; 2)views_json - Output as Simile/Exhibit JSON, canonical JSON, JSONP; 3)views_rdf - Output as FOAF, SIOC and DOAP; - 4)views_xhtml - Output as hCard, hCalendar, and Geo. \ No newline at end of file + 4)views_xhtml - Output as hCard, hCalendar, and Geo. + +To use these plugins you should: +1) Enable all four modules; +2) Set the row style plugin for your view to Unformatted; +3) In the Unformatted row style plugin options set the separator to "|" (it is + set to this by default.) +4) Set the view style plugin to one of: + i) JSON data document + ii) XML data document + iii) RDF data document + iv) XHTML data document \ No newline at end of file Index: json_plugin_style.inc =================================================================== RCS file: json_plugin_style.inc diff -N json_plugin_style.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ json_plugin_style.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,32 @@ + 'radios', + '#title' => t('JSON data format'), + '#options' => array('Simple' => t('Simple'), 'Exhibit' => t('MIT Simile/Exhibit')), + '#default_value' => $this->options['format'], + ); + } + +} Index: views-view-xml.tpl.php =================================================================== RCS file: views-view-xml.tpl.php diff -N views-view-xml.tpl.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views-view-xml.tpl.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,110 @@ +style_plugin->row_plugin) !== 'unformatted_plugin_row') { + print ('The row plugin is not of type Unformatted.'); + return; +} +else if (($view->style_plugin->row_plugin->options['separator']) !== '|') { + print ('The row plugin separator is not "|" (you can set this in the options for the row style plugin.)'); + return; +} + +$nodes = array(); +foreach($rows as $row) { + $nodes[] = explode("|", trim($row)); + +} + +if ($options['schema'] == 'raw') xml_raw_render($nodes, $view); +if ($options['schema'] == 'opml') xml_opml_render($nodes, $view); + +function xml_raw_render($nodes, $view) { + $xml .= ''."\n"; + $xml .= ''."\n"; + $xml .=''."\n"; + + foreach ($nodes as $node) { + $xml .= ' '."\n"; + foreach($node as $nodefield) { + $nodefieldarray = explode(":", $nodefield); + + /*replace escaped colons with actual colon*/ + $nodefieldarray[0] = str_replace('#colon#', ':', $nodefieldarray[0]); + $nodefieldarray[1] = str_replace('#colon#', ':', $nodefieldarray[1]); + + $label = views_xml_strip_illegal_chars($nodefieldarray[0]); + $value = views_xml_strip_illegal_chars(views_xml_is_date($nodefieldarray[1])); + if (strtotime($value)) + $value = date(DATE_ISO8601, strtotime($value)); + $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields + if (is_null($value) || ($value === '')) continue; + $xml .= " <$label>$value\n"; + } + $xml .= ' '."\n"; + } + $xml .=''."\n"; + if ($view->override_path) //inside live preview + print htmlspecialchars($xml); + else { + drupal_set_header('Content-Type: text/xml'); + print $xml; + module_invoke_all('exit'); + exit; + } +} + +function xml_opml_render($nodes, $view) { + //var_dump($view); + //return; + global $user; + $xml .= ''."\n"; + $xml .= ''."\n"; + $xml .=''."\n"; + $xml .=''."\n"; + $xml .=' '.variable_get('site_name', 'drupal').'-'.$view->name.''."\n"; + $xml .=' '.$user->name.''."\n"; + $xml .=' '.$user->mail.''."\n"; + $xml .=' '.date(DATE_ISO8601, time()).''."\n"; + $xml .=''."\n"; + $xml .=''."\n"; + foreach ($nodes as $node) { + $xml .= ' override_path) //inside live preview + print htmlspecialchars($xml); + else { + drupal_set_header('Content-Type: text/xml'); + print $xml; + module_invoke_all('exit'); + exit; + } +} Index: views-view-xhtml.tpl.php =================================================================== RCS file: views-view-xhtml.tpl.php diff -N views-view-xhtml.tpl.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views-view-xhtml.tpl.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,258 @@ +style_plugin->row_plugin) !== 'unformatted_plugin_row') { + print ('The row plugin is not of type Unformatted.'); + return; +} +else if (($view->style_plugin->row_plugin->options['separator']) !== '|') { + print ('The row plugin separator is not "|" (you can set this in the options for the row style plugin.)'); + return; +} + +$nodes = array(); +foreach($rows as $row) { + $nodes[] = explode("|", trim($row)); + +} +if (count($nodes) != count($rows)) { + print ("Did not get all rows (is the field separator '|' ?)"); + return; +} + +if ($options['format'] == 'hcard') xhtml_hcard_render($nodes, $view); + +function xhtml_hcard_render($nodes, $view) { + $xhtml .= ''."\n"; + $xhtml .= '\r\n"; + $xhtml .= ''."\r\n"; + $xhtml .= ' '."\r\n"; + $xhtml .= ' '."\r\n"; + $xhtml .= ' hCards'."\r\n"; + $xhtml .= ''."\r\n"; + $xhtml .= ''."\r\n"; + foreach ($nodes as $node) { + $hcard = array('adr'=> array( + 'type' => '', + 'post-office-box' => '', + 'street-address' => array(), + 'extended-address' => '', + 'region' => '', + 'locality' => '', + 'postal-code' => '', + 'country-name' => '' + ), + 'agent' => array(), + 'bday' => '', + 'class' => '', + 'category' => array(), + 'email' => array(), + 'fn' => '', + 'n' => array( + 'honorific-prefix' => '', + 'given-name' => '', + 'additional-name' => '', + 'family-name' => '', + 'honorific-suffix' => '' + ), + 'nickname' => '', + 'org' => array ( + 'organization-name' => '', + 'organization-unit' => array() + ), + 'photo' => '', + 'tel'=> array() + ); + foreach($node as $nodefield) { + $nodefieldarray = explode(":", $nodefield); + + /*replace escaped colons with actual colon*/ + $nodefieldarray[0] = str_replace('#colon#', ':', $nodefieldarray[0]); + $nodefieldarray[1] = str_replace('#colon#', ':', $nodefieldarray[1]); + + $label = views_xhtml_strip_illegal_chars($nodefieldarray[0]); + $value = views_xhtml_strip_illegal_chars(views_xhtml_is_date($nodefieldarray[1])); + if (strtotime($value)) + $value = date(DATE_ISO8601, strtotime($value)); + $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields + if (is_null($value) || ($value === '')) continue; + + if (stripos($label, 'address-type') !== FALSE) { + $hcard['adr']['type'] = $value; + } + if (stripos($label, 'post-office-box') !== FALSE) { + $hcard['adr']['post-office-box'] = $value; + } + if (stripos($label, 'street-address') !== FALSE) { + $hcard['adr']['street-address'][] = $value; + } + if (stripos($label, 'extended-address') !== FALSE) { + $hcard['adr']['extended-address'] = $value; + } + if (stripos($label, 'region') !== FALSE) { + $hcard['adr']['region'] = $value; + } + if (stripos($label, 'locality') !== FALSE) { + $hcard['adr']['locality'] = $value; + } + if (stripos($label, 'postal-code') !== FALSE) { + $hcard['adr']['postal-code'] = $value; + } + if (stripos($label, 'country-name') !== FALSE) { + $hcard['adr']['country-name'] = $value; + } + if (stripos($label, 'agent') !== FALSE) { + $hcard['agent'][] = $value; + } + if (stripos($label, 'bday') !== FALSE) { + $hcard['bday'] = $value; + } + if (stripos($label, 'class') !== FALSE) { + $hcard['class'] = $value; + } + if (stripos($label, 'category') !== FALSE) { + $hcard['category'][] = $value; + } + if (stripos($label, 'email') !== FALSE) { + $hcard['email'][$label] = $value; + } + if (stripos($label, 'honorific-prefix') !== FALSE) { + $hcard['n']['honorific-prefix'] = $value; + } + if (stripos($label, 'given-name') !== FALSE) { + $hcard['n']['given-name'] = $value; + } + if (stripos($label, 'additional-name') !== FALSE) { + $hcard['n']['additional-name'] = $value; + } + if (stripos($label, 'family-name') !== FALSE) { + $hcard['n']['family-name'] = $value; + } + if (stripos($label, 'honorific-suffix') !== FALSE) { + $hcard['n']['honorific-suffix'] = $value; + } + if (stripos($label, 'fn') !== FALSE) { + $hcard['fn'] = $value; + } + if (stripos($label, 'nickname') !== FALSE) { + $hcard['nickname'] = $value; + } + if (stripos($label, 'organization-name') !== FALSE) { + $hcard['org']['organization-name'] = $value; + } + if (stripos($label, 'organization-unit') !== FALSE) { + $hcard['org']['organization-unit'][] = $value; + } + if (stripos($label, 'photo') !== FALSE) { + $hcard['photo'] = $value; + } + if (stripos($label, 'tel') === 0) { + $hcard['tel'][$label] = $value; + } + } + $xhtml .= '
'."\r\n"; + if ($hcard['photo'] != '') + $xhtml .=' photo'."
\r\n"; + if ($hcard['fn']) + $xhtml .=' '.$hcard['fn'].''."
\r\n"; + if ($hcard['nickname']) + $xhtml .=' '.$hcard['nickname'].''."
\r\n"; + $name = $hcard['n']; + if ($hcard['fn']) + $xhtml .= ' '."\r\n"; + else + $xhtml .= ' '."\r\n"; + if ($name['honorific-prefix'] !== '') + $xhtml .=' '.$name['honorific-prefix'].''."\r\n"; + if ($name['given-name'] !== '') + $xhtml .=' '.$name['given-name'].''."\r\n"; + if ($name['additional-name'] !== '') + $xhtml .=' '.$name['additional-name'].''."\r\n"; + if ($name['family-name'] !== '') + $xhtml .=' '.$name['family-name'].''."\r\n"; + if ($name['honorific-suffix'] !== '') + $xhtml .=' '.$name['honorific-suffix'].''."\r\n"; + $xhtml .= '
'."\r\n"; + if ($hcard['nickname'] !== '') + $xhtml .= ' '.$hcard['nickname'].'
'."\r\n"; + $org = $hcard['org']; + $xhtml .= ' '."\r\n"; + if ($org['organization-name'] !== '') + $xhtml.= ' '.$org['organization-name'].'
'."\r\n"; + $org_units = $org['organization-unit']; + foreach ($org_units as $org_unit) + $xhtml .=' '.$org_unit.''."
\r\n"; + $xhtml .= '
'."\r\n"; + $address = $hcard['adr']; + $xhtml .= ' '."\r\n"; + if ($address['type'] !== '') + $xhtml .=' '.$address['type'].''."
\r\n"; + if ($address['post-office-box'] !== '') + $xhtml .=' '.$address['post-office-box'].''."
\r\n"; + $street_addresses = $address['street-address']; + foreach ($street_addresses as $street_address) + $xhtml .=' '.$street_address.''."
\r\n"; + if ($address['extended-address'] !== '') + $xhtml .=' '.$address['extended-address'].''."
\r\n"; + if ($address['region'] !== '') + $xhtml .=' '.$address['region'].''."
\r\n"; + if ($address['locality'] !== '') + $xhtml .=' '.$address['locality'].''."
\r\n"; + if ($address['postal-code'] !== '') + $xhtml .=' '.$address['postal-code'].''."
\r\n"; + if ($address['country-name'] !== '') + $xhtml .=' '.$address['country-name'].''."\r\n"; + $xhtml .= '

'."\r\n"; + $agents = $hcard['agent']; + foreach ($agents as $agent) + $xhtml .=' '.$agent.''."
\r\n"; + $birthday = $hcard['bday']; + if ($birthday !== '') + $xhtml .=' '.$birthday.''."
\r\n"; + $class = $hcard['class']; + if ($class !== '') + $xhtml .=' '.$class.''."
\r\n"; + $categories = $hcard['category']; + foreach ($categories as $category) + $xhtml .=' '.$category.''."
\r\n"; + if ($hcard['email']) { + $email_addrs = $hcard['email']; + foreach ($email_addrs as $email_type => $email_addr) + $xhtml .=' '."
\r\n"; + + } + if ($hcard['tel']) { + $tel_nos = $hcard['tel']; + foreach ($tel_nos as $tel_no_type => $tel_no) + $xhtml .=' '. + ''.$tel_no_type.': '. + ''.$tel_no.''. + ''."
\r\n"; + } + $xhtml .= '
'."\r\n"; + } + + $xhtml.=''."\r\n"; + $xhtml.=''."\r\n"; + if ($view->override_path) //inside live preview + print htmlspecialchars($xhtml); + else { + print $xhtml; + module_invoke_all('exit'); + exit; + } +} Index: views_xhtml.info =================================================================== RCS file: views_xhtml.info diff -N views_xhtml.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xhtml.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +name = Views XHTML +description = "Views style plugin to render node content as XHTML microformats." +package = Views Datasource +dependencies[] = views_datasource +core = 6.x + Index: views_rdf.module =================================================================== RCS file: views_rdf.module diff -N views_rdf.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_rdf.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,58 @@ + 2, + ); +} + +/** + * Strips illegal Unicode characters and encodes entities in string + * + * @param string $input + * @return string + */ +function views_rdf_strip_illegal_chars($input) { + $output = preg_replace('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP + '\x{01}-\x{1F}'. //Non-printable ASCII characters + '\x{AD}'. // Soft-hyphen + '\x{2000}-\x{200F}'. // Various space characters + '\x{2028}-\x{202F}'. // Bidirectional text overrides + '\x{205F}-\x{206F}'. // Various text hinting characters + '\x{FEFF}'. // Byte order mark + '\x{FF01}-\x{FF60}'. // Full-width latin + '\x{FFF9}-\x{FFFD}'. // Replacement characters + '\x{0}]/u', // NULL byte + '', $input); + $output = str_replace('"', '"', $output); //encode quote + $output = str_replace('&', '&', $output); //encode ampersand + $output = str_replace("'", '&pos;', $output); //encode apostrophe + $output = str_replace('<', '<', $output); //encode left-angled bracket + $output = str_replace('>', '&rt;', $output); //encode right-angled bracket + return $output; +} + +/** + * If input is a serialized date array, return a date string + * + * @param unknown_type $input + * @return unknown + */ +function views_rdf_is_date ($input) { + if (strpos($input, 'a:3:{s:5:"month"') !== 0) return $input; + else { //serialized date array + $date = unserialize($input); + return date(DATE_ISO8601, mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); + } +} Index: rdf_plugin_style.inc =================================================================== RCS file: rdf_plugin_style.inc diff -N rdf_plugin_style.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ rdf_plugin_style.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ + 'radios', + '#title' => t('RDF vocabulary'), + '#options' => array('FOAF' => t('FOAF')), + '#default_value' => $this->options['format'], + ); + } + +} Index: views_xml.module =================================================================== RCS file: views_xml.module diff -N views_xml.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xml.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ + 2, + ); +} + +/** + * Strips illegal Unicode characters and encodes entities in string + * + * @param string $input + * @return string + */ +function views_xml_strip_illegal_chars($input) { + $output = preg_replace('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP + '\x{01}-\x{1F}'. //Non-printable ASCII characters + '\x{AD}'. // Soft-hyphen + '\x{2000}-\x{200F}'. // Various space characters + '\x{2028}-\x{202F}'. // Bidirectional text overrides + '\x{205F}-\x{206F}'. // Various text hinting characters + '\x{FEFF}'. // Byte order mark + '\x{FF01}-\x{FF60}'. // Full-width latin + '\x{FFF9}-\x{FFFD}'. // Replacement characters + '\x{0}]/u', // NULL byte + '', $input); + $output = str_replace('"', '"', $output); //encode quote + $output = str_replace('&', '&', $output); //encode ampersand + $output = str_replace("'", '&pos;', $output); //encode apostrophe + $output = str_replace('<', '<', $output); //encode left-angled bracket + $output = str_replace('>', '&rt;', $output); //encode right-angled bracket + return $output; +} + +function views_xml_is_date ($input) { + if (strpos($input, 'a:3:{s:5:"month"') !== 0) return $input; + else { //serialized date array + $date = unserialize($input); + return date(DATE_ISO8601, mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); + } +} Index: views_xhtml.module =================================================================== RCS file: views_xhtml.module diff -N views_xhtml.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xhtml.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ + 2, + ); +} + +/** + * Strips illegal Unicode characters and encodes entities in string + * + * @param string $input + * @return string + */ +function views_xhtml_strip_illegal_chars($input) { + $output = preg_replace('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP + '\x{01}-\x{1F}'. //Non-printable ASCII characters + '\x{AD}'. // Soft-hyphen + '\x{2000}-\x{200F}'. // Various space characters + '\x{2028}-\x{202F}'. // Bidirectional text overrides + '\x{205F}-\x{206F}'. // Various text hinting characters + '\x{FEFF}'. // Byte order mark + '\x{FF01}-\x{FF60}'. // Full-width latin + '\x{FFF9}-\x{FFFD}'. // Replacement characters + '\x{0}]/u', // NULL byte + '', $input); + $output = str_replace('"', '"', $output); //encode quote + $output = str_replace('&', '&', $output); //encode ampersand + $output = str_replace("'", '&pos;', $output); //encode apostrophe + $output = str_replace('<', '<', $output); //encode left-angled bracket + $output = str_replace('>', '&rt;', $output); //encode right-angled bracket + return $output; +} + +function views_xhtml_is_date ($input) { + if (strpos($input, 'a:3:{s:5:"month"') !== 0) return $input; + else { //serialized date array + $date = unserialize($input); + return date(DATE_ISO8601, mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); + } +} Index: views-view-rdf.tpl.php =================================================================== RCS file: views-view-rdf.tpl.php diff -N views-view-rdf.tpl.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views-view-rdf.tpl.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,147 @@ +style_plugin->row_plugin) !== 'unformatted_plugin_row') { + print ('The row plugin is not of type Unformatted.'); + return; +} +else if (($view->style_plugin->row_plugin->options['separator']) !== '|') { + print ('The row plugin separator is not "|" (you can set this in the options for the row style plugin.)'); + return; +} + +$nodes = array(); +foreach($rows as $row) { + $nodes[] = explode("|", trim($row)); + +} + +if ($options['vocabulary'] == 'FOAF') rdf_foaf_xml_render($nodes, $view); + +/** + * Render nodes as FOAF in XML + * + * @param array $nodes + * @return none + */ +function rdf_foaf_xml_render($nodes, $view) { + $xml .= ''."\n"; + $xml .= ''."\n"; + $xml .= '") == false) + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'title') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'nick') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'mbox_sha1sum') !== false) { + $xml.=" $value\n"; + continue; + } + if ((stripos($label, 'mbox') !== false) && !(stripos($label, 'mbox_sha1sum') !== false)) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'openid') !== false) { + $xml.=" $value\n"; + continue; + } + if (strpos($label, 'workplaceHomepage') !== false) { + $xml.=' '."\n"; + continue; + } + if (strpos($label, 'homepage') !== false) { + $xml.=' '."\n"; + continue; + } + if (stripos($label, 'weblog') !== false) { + $xml.=' '."\n"; + continue; + } + if (strpos($label, 'img') !== false) { + $xml.=' '."\n"; + $xml.=' '."\n"; + continue; + } + if (stripos($label, 'member') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'phone') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'jabberID') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'msnChatID') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'aimChatID') !== false) { + $xml.=" $value\n"; + continue; + } + if (stripos($label, 'yahooChatID') !== false) { + $xml.=" $value\n"; + continue; + } + } + $xml.="\n"; + } + $xml.="\n"; + if ($view->override_path) //inside live preview + print htmlspecialchars($xml); + else { + print $xml; + module_invoke_all('exit'); + exit; + } + +} + Index: views_xml.views.inc =================================================================== RCS file: views_xml.views.inc diff -N views_xml.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xml.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ + array( //declare the views_xml_* style plugins + 'views_xml' => array( + 'title' => t('XML data document'), + 'theme' => 'views_view_xml', + 'help' => t('Displays nodes as XML.'), + 'handler' => 'xml_plugin_style', + 'uses row plugin' => TRUE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + ), + ), + ); +} + +/** + * Theme preprocess function for views-view-xml.tpl.php + * + * @param array $vars + */ +function template_preprocess_views_view_xml(&$vars) { + $view = &$vars['view']; + $options = $view->style_handler->options; + $handler = $view->style_handler; +} + Index: views_datasource.module =================================================================== RCS file: views_datasource.module diff -N views_datasource.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_datasource.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ + 2, + ); +} Index: views_datasource.views.inc =================================================================== RCS file: views_datasource.views.inc diff -N views_datasource.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_datasource.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,58 @@ + array( //declare the unformatted row plugin + 'unformatted' => array( + 'title' => t('Unformatted'), + 'help' => t('(Displays the unformatted data for each row from the views query with each row on a new line. Set as | for views_json.'), + 'handler' => 'unformatted_plugin_row', + 'theme' => 'views_view_row_unformatted', + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + ) + ) + ); +} + +/** + * Theme preprocess function for views-view-row-unformatted.tpl.php + */ +function template_preprocess_views_view_row_unformatted(&$vars) { + $view = $vars['view']; + //print('preprocess'); + // Loop through the fields for this view. + foreach ($view->field as $id => $field) { + if (!empty($field->handler) && is_object($field->handler)) { + $object = new stdClass(); + $object->content = $field['handler']->theme($vars['row']); + if (isset($field['handler']->field_alias) && isset($vars['row']->{$field['handler']->field_alias})) { + $object->raw = $vars['row']->{$field['handler']->field_alias}; + } + else { + $object->raw = NULL; // make sure it exists to reduce NOTICE + } + if (!empty($vars['options']['separator']) && $object->content) { + $object->separator = filter_xss($vars['options']['separator']); + } + + $object->handler = $field['handler']; + $object->class = views_css_safe($id); + $object->label = check_plain($field['handler']->label()); + $vars['fields'][$id] = $object; + } + } + +} Index: views_rdf.info =================================================================== RCS file: views_rdf.info diff -N views_rdf.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_rdf.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +name = Views RDF +description = "Views style plugin to render node content as RDF." +package = Views Datasource +dependencies[] = views_datasource +core = 6.x + Index: views_rdf.views.inc =================================================================== RCS file: views_rdf.views.inc diff -N views_rdf.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_rdf.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ + array( //declare the views_rdf style plugin + 'views_rdf' => array( + 'title' => t('RDF data document'), + 'theme' => 'views_view_rdf', + 'help' => t('Displays nodes in the RDF data format.'), + 'handler' => 'rdf_plugin_style', + 'uses row plugin' => TRUE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + ), + ), + ); +} + + +/** + * Theme preprocess function for views-view-rdf.tpl.php + * + * @param array $vars + */ +function template_preprocess_views_view_rdf(&$vars) { + $view = &$vars['view']; + $options = $view->style_handler->options; + $handler = $view->style_handler; +} Index: xml_plugin_style.inc =================================================================== RCS file: xml_plugin_style.inc diff -N xml_plugin_style.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ xml_plugin_style.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ + 'radios', + '#title' => t('Schema'), + '#options' => array('raw' => t('raw'),'opml'=> t('opml')), + '#default_value' => $this->options['schema'], + ); + } + +} Index: xhtml_plugin_style.inc =================================================================== RCS file: xhtml_plugin_style.inc diff -N xhtml_plugin_style.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ xhtml_plugin_style.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ + 'radios', + '#title' => t('Microformat'), + '#options' => array('hcard' => t('hCard')), + '#default_value' => $this->options['format'], + ); + } + +} Index: unformatted_plugin_row.inc =================================================================== RCS file: unformatted_plugin_row.inc diff -N unformatted_plugin_row.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ unformatted_plugin_row.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,42 @@ +'|'); + return $options; + } + + /** + * Provide a form for setting options. + */ + function options_form(&$form, &$form_state) { + $fields = $this->display->handler->get_option('fields'); + $options = array(); + foreach ($fields as $field => $info) { + $handler = views_get_handler($info['table'], $info['field'], 'field'); + if ($handler) { + $options[$field] = $handler->ui_name(); + } + } + + $form['separator'] = array( + '#title' => t('Separator'), + '#type' => 'textfield', + '#size' => 10, + '#default_value' => isset($this->options['separator']) ? $this->options['separator'] : ',', + '#description' => t('The separator is placed between fields.'), + ); + } + +} Index: views_xhtml.views.inc =================================================================== RCS file: views_xhtml.views.inc diff -N views_xhtml.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xhtml.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,40 @@ + array( //declare the views_xhtml style plugin + 'views_xhtml' => array( + 'title' => t('XHTML data document'), + 'theme' => 'views_view_xhtml', + 'help' => t('Displays nodes as XHTML microformats.'), + 'handler' => 'xhtml_plugin_style', + 'uses row plugin' => TRUE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + ), + ), + ); +} + +/** + * Theme preprocess function for views-view-xhtml.tpl.php + * + * @param array $vars + */ +function template_preprocess_views_view_xhtml(&$vars) { + $view = &$vars['view']; + $options = $view->style_handler->options; + $handler = $view->style_handler; +} Index: views_xml.info =================================================================== RCS file: views_xml.info diff -N views_xml.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_xml.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +name = Views XML +description = "Views style plugin to render node content as XML" +package = Views Datasource +dependencies[] = views_datasource +core = 6.x + Index: views_datasource.info =================================================================== RCS file: views_datasource.info diff -N views_datasource.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views_datasource.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +name = Views Datasource +description = "Views style plugin to render node content as different data types." +package = Views Datasource +dependencies[] = views +core = 6.x