From ef4591315b719f96c811bdc2a6b630b23558079b Mon Sep 17 00:00:00 2001 From: nbboob Date: Wed, 20 Jun 2012 15:29:28 +0200 Subject: [PATCH 01/14] first version --- arxiv.info | 2 +- arxiv.install | 47 ++++++++++++++++++++ arxiv.module | 121 +++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 arxiv.install diff --git a/arxiv.info b/arxiv.info index 33bccc9..a086077 100755 --- a/arxiv.info +++ b/arxiv.info @@ -1,4 +1,4 @@ ; $Id: arxiv.info,v 1.0 $ name = Arxiv description = Get paper from arxiv.org. -core = 7.x \ No newline at end of file +core = 7.x diff --git a/arxiv.install b/arxiv.install new file mode 100644 index 0000000..a6f919a --- /dev/null +++ b/arxiv.install @@ -0,0 +1,47 @@ + 'Stores paper download number information.', + 'fields' => array( + 'nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'node ID.', + ), + 'downloadNo' => array ( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'download number' + ), + ), + 'primary key' => array('nid'), + 'indexes' => array( + 'dn' => array('downloadNo'), + ), + ); + + return $schema; +} + +/** + * Implements hook_uninstall(). + */ +function arxiv_uninstall() { + $del = db_delete('variable') + ->condition('name', 'arxiv_%', 'LIKE') + ->execute(); +} \ No newline at end of file diff --git a/arxiv.module b/arxiv.module index 31425d5..cef99cd 100755 --- a/arxiv.module +++ b/arxiv.module @@ -10,12 +10,8 @@ function arxiv_field_info() { 'default_formatter' => 'arxiv_default', 'settings' => array ( 'max_length' => 9 - ), - - - ), - - + ), + ), ); } @@ -196,8 +192,16 @@ function arxiv_field_formatter_info() { ), - 'arxiv_plain' => array ( - 'label' => t('Plain text'), + 'arxiv_download' => array ( + 'label' => t('Plain text with download link only'), + 'field types' => array ( + 'arxiv' + ), + + + ), + 'arxiv_abstract' => array ( + 'label' => t('Plain text with abstract info only'), 'field types' => array ( 'arxiv' ), @@ -211,21 +215,29 @@ function arxiv_field_formatter_info() { function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array (); - + $statistics = statistics_get($entity->nid); + $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) + ->condition('m.nid', $entity->nid)->execute()->fetchAll(); + if($obj){ + $info = ' ('.$statistics['totalcount'].' views, '.$obj[0]->downloadNo.' download, '.$entity->comment_count.' comments)'; + }else{ + $info = ' ('.$statistics['totalcount'].' views, 0 download, '.$entity->comment_count.' comments)'; + } + switch ($display['type']) { case 'arxiv_default' : foreach ($items as $delta => $item) { - $output = '

' . $item['authors'] . '

' . $item['abstract'] . '

'; + $output = '

' . $item['abstract'] . '

'; if ($item['pdfUrl'] != '') { - $output .= 'pdf '; + $output .= 'pdf '; } if ($item['psUrl'] != '') { - $output .= 'ps '; + $output .= 'ps '; } if ($item['otherUrl'] != '') { - $output .= 'other '; + $output .= 'other '; } - $output .= '

'; + $output .= $info.'

'; $element[$delta] = array ( '#markup' => $output ); @@ -233,23 +245,33 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l break; - case 'arxiv_plain' : + case 'arxiv_download' : foreach ($items as $delta => $item) { - $output = '

' . $item['authors'] . '

'; + $output = '

'; if ($item['pdfUrl'] != '') { - $output .= 'pdf '; + $output .= 'pdf '; } if ($item['psUrl'] != '') { - $output .= 'ps '; + $output .= 'ps '; } if ($item['otherUrl'] != '') { - $output .= 'other '; + $output .= 'other '; } - $output .= '

'; + $output .= $info.'

'; + $element[$delta] = array ( + '#markup' => $output + ); + } + break; + + case 'arxiv_abstract' : + foreach ($items as $delta => $item) { + $output = '

' . $item['abstract'] . '

'; $element[$delta] = array ( '#markup' => $output ); } + break; } @@ -332,7 +354,7 @@ function arxiv_get_paper($serialNo) { } function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { - foreach($form_state['field'] as $type=>$name){ + foreach($form_state['field'] as $type=>$name){ if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ $form['title']['#value'] = 'ant'; $form['title']['#type'] = 'value'; @@ -341,4 +363,61 @@ function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { } } +} + +/** + * Implementation of hook_menu(). + */ +function arxiv_menu() { + $items['paper/download/%/%'] = array( + // 'page callback' => 'postform_overlay', + 'title'=>'Download the paper', + 'page callback' => 'paper_download', + 'page arguments' => array(2,3), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK + ); + return $items; +} + +function paper_download($nid,$type){ + $node = node_load($nid); + $langcode = $GLOBALS['language_content']->language; + node_build_content($node, 'full', $langcode); + list(, , $bundle) = entity_extract_ids('node', $node); + //increase download number + $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) + ->condition('m.nid', $node->nid)->execute()->fetchAll(); + if($obj){ + db_update('arxiv_downNo')->fields(array ('downloadNo'=>$obj[0]->downloadNo+1)) + ->condition('nid', $node->nid)->execute(); + }else{ + db_insert('arxiv_downNo')->fields(array ('nid'=>$node->nid,'downloadNo'=>1))->execute(); + } + + //download + foreach (field_info_instances('node', $bundle) as $instance) { + if($instance['widget']['module']=='arxiv'){ + if ($node->{$instance['field_name']}['und'][0]['pdfUrl'] != ''&& $type=='pdf') { + $url=$node->{$instance['field_name']}['und'][0]['pdfUrl']; + header( "Location: $url" ); + // return $node->{$instance['field_name']}['und'][0]['pdfUrl']; + } + if ($node->{$instance['field_name']}['und'][0]['psUrl'] != ''&&$type=='ps') { + $url=$node->{$instance['field_name']}['und'][0]['psUrl']; + header( "Location: $url" ); + //return $node->{$instance['field_name']}['und'][0]['psUrl']; + } + if ($node->{$instance['field_name']}['und'][0]['otherUrl'] != ''&&$type=='other') { + $url=$node->{$instance['field_name']}['und'][0]['otherUrl']; + header( "Location: $url" ); + } + }else if($instance['field_name']=='field_upload'){ + if ($node->{$instance['field_name']}['und'][0]['filename'] != '') { + $url = file_create_url(http://github.com/$node-%3E%7B$instance['field_name']%7D['und'][0]['uri']); + header( "Location: $url" ); + } + } + } + } \ No newline at end of file From 97fa144ee8d943f7ce2bb2d28d6abae2d358d53c Mon Sep 17 00:00:00 2001 From: nbboob Date: Tue, 26 Jun 2012 16:31:12 +0200 Subject: [PATCH 02/14] set dependencies --- arxiv.info | 1 + arxiv.module | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arxiv.info b/arxiv.info index a086077..b85666a 100755 --- a/arxiv.info +++ b/arxiv.info @@ -2,3 +2,4 @@ name = Arxiv description = Get paper from arxiv.org. core = 7.x +dependencies[] = statistics diff --git a/arxiv.module b/arxiv.module index cef99cd..d3431d7 100755 --- a/arxiv.module +++ b/arxiv.module @@ -85,7 +85,7 @@ function _arxiv_field_validate($element, & $form_state) { ))->condition('m.' . $field_name . '_serialNo', $item['text_field_wrapper']['arxivinfo'])->condition('m.deleted', 0)->execute()->fetchAll(); if ($obj) - form_set_error($field_name, t('The paper you submitted already exists. Click here to view it.')); + form_set_error($field_name, t('The paper you submitted already exists. Click here to view it.')); else { include_once (ARXIV_PATH . '/parser/BrowserEmulator.php'); $html = BrowserEmulator :: openArxiv($item['text_field_wrapper']['arxivinfo']); @@ -229,13 +229,13 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l foreach ($items as $delta => $item) { $output = '

' . $item['abstract'] . '

'; if ($item['pdfUrl'] != '') { - $output .= 'pdf '; + $output .= 'pdf '; } if ($item['psUrl'] != '') { - $output .= 'ps '; + $output .= 'ps '; } if ($item['otherUrl'] != '') { - $output .= 'other '; + $output .= 'other '; } $output .= $info.'

'; $element[$delta] = array ( @@ -249,13 +249,13 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l foreach ($items as $delta => $item) { $output = '

'; if ($item['pdfUrl'] != '') { - $output .= 'pdf '; + $output .= 'pdf '; } if ($item['psUrl'] != '') { - $output .= 'ps '; + $output .= 'ps '; } if ($item['otherUrl'] != '') { - $output .= 'other '; + $output .= 'other '; } $output .= $info.'

'; $element[$delta] = array ( From 91bece6fea30921a498f0a23f5d7e75536bfecc5 Mon Sep 17 00:00:00 2001 From: nbboob Date: Thu, 11 Oct 2012 19:22:35 +0200 Subject: [PATCH 03/14] improvement --- arxiv.module | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arxiv.module b/arxiv.module index d3431d7..0f5bc4e 100755 --- a/arxiv.module +++ b/arxiv.module @@ -95,7 +95,7 @@ function _arxiv_field_validate($element, & $form_state) { } // serial id doesn't exist - if ($html == '' || strpos($html, "Paper identifier " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== false || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== false) { + if ($html == '' || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== false || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== false) { form_set_error($field_name, t('The paper you submitted does not exist.')); return; } @@ -220,8 +220,10 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l ->condition('m.nid', $entity->nid)->execute()->fetchAll(); if($obj){ $info = ' ('.$statistics['totalcount'].' views, '.$obj[0]->downloadNo.' download, '.$entity->comment_count.' comments)'; - }else{ + }elseif(isset($entity->comment_count)){ $info = ' ('.$statistics['totalcount'].' views, 0 download, '.$entity->comment_count.' comments)'; + }else{ + $info = ' '; } switch ($display['type']) { @@ -327,7 +329,6 @@ function arxiv_get_paper($serialNo) { // 4) abstract $abstracts = $dom->find('.abstract'); - foreach ($abstracts[0]->find('a') as $a) { $a->outertext = $a->innertext; } @@ -356,9 +357,9 @@ function arxiv_get_paper($serialNo) { function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { foreach($form_state['field'] as $type=>$name){ if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - $form['title']['#value'] = 'ant'; - $form['title']['#type'] = 'value'; - $form['title']['#required'] = FALSE; + $form['title']['#value'] = $form_state['build_info']['args'][0]->field_serial_no['und'][0]['title']; + $form['title']['#type'] = 'value'; + $form['title']['#required'] = FALSE; break; } } From 897e309af78f5b221e0df3db91a11d71e19d74f1 Mon Sep 17 00:00:00 2001 From: nbboob Date: Mon, 15 Oct 2012 16:32:03 +0200 Subject: [PATCH 04/14] change preview error --- arxiv.module | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arxiv.module b/arxiv.module index 0f5bc4e..3af49ab 100755 --- a/arxiv.module +++ b/arxiv.module @@ -300,6 +300,7 @@ function arxiv_get_paper($serialNo) { $dom = str_get_html($html); $fulltext = $dom->find('.full-text'); $lis = $fulltext[0]->find('li'); + $item['otherUrl']='';$item['psUrl']='';$item['pdfUrl'] =''; foreach ($lis as $li) { if (strpos($li, 'PDF') !== false) { $item['pdfUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; @@ -308,7 +309,7 @@ function arxiv_get_paper($serialNo) { $item['psUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; } if (strpos($li, 'Other') !== false) { - $item['psUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; + $item['OtherUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; } } @@ -357,7 +358,11 @@ function arxiv_get_paper($serialNo) { function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { foreach($form_state['field'] as $type=>$name){ if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - $form['title']['#value'] = $form_state['build_info']['args'][0]->field_serial_no['und'][0]['title']; + if(isset($form_state['build_info']['args'][0]->field_serial_no)){ + $form['title']['#value'] = $form_state['build_info']['args'][0]->field_serial_no['und'][0]['title']; + }else{ + $form['title']['#value']='null'; + } $form['title']['#type'] = 'value'; $form['title']['#required'] = FALSE; break; From f6e397096dc7447e19437f0a15688bb57a703628 Mon Sep 17 00:00:00 2001 From: nbboob Date: Mon, 15 Oct 2012 16:44:56 +0200 Subject: [PATCH 05/14] change preview error --- arxiv.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arxiv.module b/arxiv.module index 3af49ab..ce6384d 100755 --- a/arxiv.module +++ b/arxiv.module @@ -95,7 +95,7 @@ function _arxiv_field_validate($element, & $form_state) { } // serial id doesn't exist - if ($html == '' || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== false || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== false) { + if ($html == '' || strpos($html, "Paper identifier '" . $item['text_field_wrapper']['arxivinfo'] . "' not recognized") !== false ||strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== false || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== false) { form_set_error($field_name, t('The paper you submitted does not exist.')); return; } From 2b155b22ec6380ba441b029d0b34a1fd8549ade7 Mon Sep 17 00:00:00 2001 From: nbboob Date: Mon, 15 Oct 2012 18:11:04 +0200 Subject: [PATCH 06/14] change preview error --- arxiv.module | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arxiv.module b/arxiv.module index ce6384d..168ea7e 100755 --- a/arxiv.module +++ b/arxiv.module @@ -105,7 +105,6 @@ function _arxiv_field_validate($element, & $form_state) { $new_value = arxiv_get_paper($item['text_field_wrapper']['arxivinfo']); form_set_value($element, $new_value, $form_state); } - } function arxiv_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); @@ -117,6 +116,17 @@ function arxiv_field_insert($entity_type, $entity, $field, $instance, $langcode, node_save($node); } +function arxiv_node_validate($node, $form, &$form_state) { + foreach($form_state['field'] as $type=>$name){ + if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ + if(isset($form_state['values']['field_serial_no'])){ + $form_state['values']['title']= $form_state['values']['field_serial_no']['und'][0]['title']; + } + break; + } + } +} + function arxiv_field_widget_info() { return array ( 'text_field' => array ( @@ -358,11 +368,7 @@ function arxiv_get_paper($serialNo) { function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { foreach($form_state['field'] as $type=>$name){ if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - if(isset($form_state['build_info']['args'][0]->field_serial_no)){ - $form['title']['#value'] = $form_state['build_info']['args'][0]->field_serial_no['und'][0]['title']; - }else{ - $form['title']['#value']='null'; - } + $form['title']['#value']='null'; $form['title']['#type'] = 'value'; $form['title']['#required'] = FALSE; break; From 722c85b5bc6403b8fa08495b1b7bc97f7e818488 Mon Sep 17 00:00:00 2001 From: nbboob Date: Sat, 20 Oct 2012 17:32:35 +0200 Subject: [PATCH 07/14] fix bugs of chunked transfer encoding --- parser/BrowserEmulator.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/parser/BrowserEmulator.php b/parser/BrowserEmulator.php index 4c2ca40..0cae79a 100755 --- a/parser/BrowserEmulator.php +++ b/parser/BrowserEmulator.php @@ -108,8 +108,39 @@ static function openArxiv($id) { fclose($file); - return $html; + return $be->http_chunked_decode($html); } + /** + * @param string $data + * @return string + */ + function http_chunked_decode($chunk) { + $pos = 0; + $len = strlen($chunk); + $dechunk = null; + + while(($pos < $len) + && ($chunkLenHex = substr($chunk,$pos, ($newlineAt = strpos($chunk,"\n",$pos+1))-$pos))) + { + if (! $this->is_hex($chunkLenHex)) { + trigger_error('Value is not properly chunk encoded', E_USER_WARNING); + return $chunk; + } + + $pos = $newlineAt + 1; + $chunkLen = hexdec(rtrim($chunkLenHex,"\r\n")); + $dechunk .= substr($chunk, $pos, $chunkLen); + $pos = strpos($chunk, "\n", $pos + $chunkLen) + 1; + } + return $dechunk; + } + function is_hex($hex) { + // regex is for weenies + $hex = strtolower(trim(ltrim($hex,"0"))); + if (empty($hex)) { $hex = 0; }; + $dec = hexdec($hex); + return ($hex == dechex($dec)); + } /** * Make an fopen call to $url with the parameters set by previous member From 45143daf587869535ea7f4e3ae0b20e8a8d41f9b Mon Sep 17 00:00:00 2001 From: root Date: Tue, 21 May 2013 18:00:50 +0200 Subject: [PATCH 08/14] complete the preview error issue --- arxiv.module | 440 ++++++++++++++++++++++++++------------------------- 1 file changed, 223 insertions(+), 217 deletions(-) diff --git a/arxiv.module b/arxiv.module index 168ea7e..1d4fa08 100755 --- a/arxiv.module +++ b/arxiv.module @@ -3,68 +3,68 @@ define('ARXIV_PATH', drupal_get_path('module', 'arxiv')); function arxiv_field_info() { return array ( - 'arxiv' => array ( - 'label' => t('Arxiv'), - 'description' => 'This field gets a paper from arxiv.org', - 'default_widget' => 'text_field', - 'default_formatter' => 'arxiv_default', - 'settings' => array ( - 'max_length' => 9 - ), - ), - ); + 'arxiv' => array ( + 'label' => t('Arxiv'), + 'description' => 'This field gets a paper from arxiv.org', + 'default_widget' => 'text_field', + 'default_formatter' => 'arxiv_default', + 'settings' => array ( + 'max_length' => 9 + ), + ), + ); } function arxiv_field_schema($field) { if ($field['type'] == 'arxiv') { $schema = array ( - 'columns' => array ( - 'serialNo' => array ( - 'type' => 'varchar', - 'length' => 20, - 'default' => '' - ), - 'authors' => array ( - 'type' => 'varchar', - 'length' => 100, - 'default' => '' - ), - 'abstract' => array ( - 'type' => 'varchar', - 'length' => 2000, - 'default' => '' - ), - 'pdfUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'psUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'otherUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'downloadNo' => array ( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'download number' - ), - - - ), - 'indexs' => array ( - 'serialNo' - ), - - - ); + 'columns' => array ( + 'serialNo' => array ( + 'type' => 'varchar', + 'length' => 20, + 'default' => '' + ), + 'authors' => array ( + 'type' => 'varchar', + 'length' => 100, + 'default' => '' + ), + 'abstract' => array ( + 'type' => 'varchar', + 'length' => 2000, + 'default' => '' + ), + 'pdfUrl' => array ( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'psUrl' => array ( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'otherUrl' => array ( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'downloadNo' => array ( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'download number' + ), + + + ), + 'indexs' => array ( + 'serialNo' + ), + + + ); return $schema; } @@ -80,10 +80,10 @@ function _arxiv_field_validate($element, & $form_state) { foreach ($values[$field_name][$language] as $delta => $item) { if (!empty ($item['text_field_wrapper']['arxivinfo'])) { $obj = db_select('field_data_' . $field_name, 'm')->fields('m', array ( - 'entity_type', - 'entity_id' - ))->condition('m.' . - $field_name . '_serialNo', $item['text_field_wrapper']['arxivinfo'])->condition('m.deleted', 0)->execute()->fetchAll(); + 'entity_type', + 'entity_id' + ))->condition('m.' . + $field_name . '_serialNo', $item['text_field_wrapper']['arxivinfo'])->condition('m.deleted', 0)->execute()->fetchAll(); if ($obj) form_set_error($field_name, t('The paper you submitted already exists. Click here to view it.')); else { @@ -112,59 +112,59 @@ function arxiv_field_insert($entity_type, $entity, $field, $instance, $langcode, foreach($items as $delta=>$item){ $node->title=$item['title']; } - + node_save($node); } function arxiv_node_validate($node, $form, &$form_state) { foreach($form_state['field'] as $type=>$name){ - if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - if(isset($form_state['values']['field_serial_no'])){ - $form_state['values']['title']= $form_state['values']['field_serial_no']['und'][0]['title']; - } - break; - } - } + if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ + if(isset($form_state['values']['field_serial_no'])){ + $form_state['values']['title']= $form_state['values']['field_serial_no']['und'][0]['title']; + } + break; + } + } } function arxiv_field_widget_info() { return array ( - 'text_field' => array ( - 'label' => t('Text field'), - 'desscription' => t('Allow the user to enter arxiv serial No.'), - 'field types' => array ( - 'arxiv' - ), - 'settings' => array ( - 'number' => '' - ), - 'behaviors' => array ( - 'multiple values' => FIELD_BEHAVIOR_DEFAULT, - 'default value' => FIELD_BEHAVIOR_CUSTOM, - - - ), - - - ), - - - ); + 'text_field' => array ( + 'label' => t('Text field'), + 'desscription' => t('Allow the user to enter arxiv serial No.'), + 'field types' => array ( + 'arxiv' + ), + 'settings' => array ( + 'number' => '' + ), + 'behaviors' => array ( + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + 'default value' => FIELD_BEHAVIOR_CUSTOM, + + + ), + + + ), + + + ); } function arxiv_field_widget_settings_form($field, $instance) { $form = array (); $widget = $instance['widget']; $settings = $widget['settings']; - if ($widget['type'] == 'text_field') { - $form['number'] = array ( - '#type' => 'textfield', - '#title' => t('Serial No'), - '#required' => TRUE, - '#default_value' => $settings['number'], - - - ); - } + //if ($widget['type'] == 'text_field') { + // $form['number'] = array ( + // '#type' => 'textfield', + // '#title' => t('Serial No'), + // '#required' => TRUE, + // '#default_value' => $settings['number'], + + + // ); + //} return $form; } @@ -173,8 +173,8 @@ function arxiv_field_widget_form(& $form, & $form_state, $field, $instance, $lan if ($instance['widget']['type'] == 'text_field') { $element['#element_validate'] = array ( - '_arxiv_field_validate' - ); + '_arxiv_field_validate' + ); $default = NULL; if (isset ($items[$delta])) { $item = $items[$delta]; @@ -182,60 +182,60 @@ function arxiv_field_widget_form(& $form, & $form_state, $field, $instance, $lan } $element['text_field_wrapper']['#theme'] = 'text_field_wrapper'; $element['text_field_wrapper']['arxivinfo'] = array ( - '#type' => 'textfield', - '#default_value' => $default, - '#number' => $instance['widget']['settings']['number'], + '#type' => 'textfield', + '#default_value' => $default, + '#number' => $instance['widget']['settings']['number'], - - ) + $base; + + ) + $base; } return $element; } function arxiv_field_formatter_info() { return array ( - 'arxiv_default' => array ( - 'label' => t('Default'), - 'field types' => array ( - 'arxiv' - ), - - - ), - 'arxiv_download' => array ( - 'label' => t('Plain text with download link only'), - 'field types' => array ( - 'arxiv' - ), - - - ), - 'arxiv_abstract' => array ( - 'label' => t('Plain text with abstract info only'), - 'field types' => array ( - 'arxiv' - ), - - - ), - - - ); + 'arxiv_default' => array ( + 'label' => t('Default'), + 'field types' => array ( + 'arxiv' + ), + + + ), + 'arxiv_download' => array ( + 'label' => t('Plain text with download link only'), + 'field types' => array ( + 'arxiv' + ), + + + ), + 'arxiv_abstract' => array ( + 'label' => t('Plain text with abstract info only'), + 'field types' => array ( + 'arxiv' + ), + + + ), + + + ); } function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array (); $statistics = statistics_get($entity->nid); $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) - ->condition('m.nid', $entity->nid)->execute()->fetchAll(); - if($obj){ - $info = ' ('.$statistics['totalcount'].' views, '.$obj[0]->downloadNo.' download, '.$entity->comment_count.' comments)'; - }elseif(isset($entity->comment_count)){ - $info = ' ('.$statistics['totalcount'].' views, 0 download, '.$entity->comment_count.' comments)'; - }else{ - $info = ' '; - } - + ->condition('m.nid', $entity->nid)->execute()->fetchAll(); + if($obj){ + $info = ' ('.$statistics['totalcount'].' views, '.$obj[0]->downloadNo.' download, '.$entity->comment_count.' comments)'; + }elseif(isset($entity->comment_count)){ + $info = ' ('.$statistics['totalcount'].' views, 0 download, '.$entity->comment_count.' comments)'; + }else{ + $info = ' '; + } + switch ($display['type']) { case 'arxiv_default' : foreach ($items as $delta => $item) { @@ -251,8 +251,8 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l } $output .= $info.'

'; $element[$delta] = array ( - '#markup' => $output - ); + '#markup' => $output + ); } break; @@ -271,17 +271,17 @@ function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $l } $output .= $info.'

'; $element[$delta] = array ( - '#markup' => $output - ); + '#markup' => $output + ); } break; - + case 'arxiv_abstract' : foreach ($items as $delta => $item) { $output = '

' . $item['abstract'] . '

'; $element[$delta] = array ( - '#markup' => $output - ); + '#markup' => $output + ); } break; @@ -305,8 +305,8 @@ function arxiv_get_paper($serialNo) { include_once (ARXIV_PATH . '/parser/BrowserEmulator.php'); $html = BrowserEmulator :: openArxiv($serialNo); $item = array ( - 'serialNo' => $serialNo - ); + 'serialNo' => $serialNo + ); $dom = str_get_html($html); $fulltext = $dom->find('.full-text'); $lis = $fulltext[0]->find('li'); @@ -346,16 +346,16 @@ function arxiv_get_paper($serialNo) { $arxivAbstract = $abstracts[0]->innerText(); $arxivAbstract = substr($arxivAbstract, strpos($arxivAbstract, '') + 7); // 7 is the length of '' $arxivAbstract = html_entity_decode($arxivAbstract, ENT_QUOTES, 'utf-8'); - + if (strlen($arxivAuthor) > 100) { - $arxivAuthor=substr($arxivAuthor,0,95).'...'; - } - if (strlen($arxivAbstract) > 2000) { - $arxivAbstract=substr($arxivAbstract,0,1995).'...'; - } - if (strlen($arxivTitle) > 255) { - $arxivTitle=substr($arxivTitle,0,250).'...'; - } + $arxivAuthor=substr($arxivAuthor,0,95).'...'; + } + if (strlen($arxivAbstract) > 2000) { + $arxivAbstract=substr($arxivAbstract,0,1995).'...'; + } + if (strlen($arxivTitle) > 255) { + $arxivTitle=substr($arxivTitle,0,250).'...'; + } $item['title'] = $arxivTitle; @@ -366,70 +366,76 @@ function arxiv_get_paper($serialNo) { } function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { - foreach($form_state['field'] as $type=>$name){ - if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - $form['title']['#value']='null'; - $form['title']['#type'] = 'value'; - $form['title']['#required'] = FALSE; - break; - } - } + foreach($form_state['field'] as $type=>$name){ + if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ + $form['title']['#value']='null'; + $form['title']['#type'] = 'value'; + $form['title']['#required'] = FALSE; + break; + } + } } /** * Implementation of hook_menu(). - */ + */ function arxiv_menu() { - $items['paper/download/%/%'] = array( - // 'page callback' => 'postform_overlay', - 'title'=>'Download the paper', - 'page callback' => 'paper_download', - 'page arguments' => array(2,3), - 'access callback' => TRUE, - 'type' => MENU_CALLBACK - ); - return $items; + $items['paper/download/%/%'] = array( + // 'page callback' => 'postform_overlay', + 'title'=>'Download the paper', + 'page callback' => 'paper_download', + 'page arguments' => array(2,3), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK + ); + return $items; } function paper_download($nid,$type){ $node = node_load($nid); - $langcode = $GLOBALS['language_content']->language; - node_build_content($node, 'full', $langcode); - list(, , $bundle) = entity_extract_ids('node', $node); - //increase download number - $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) - ->condition('m.nid', $node->nid)->execute()->fetchAll(); - if($obj){ - db_update('arxiv_downNo')->fields(array ('downloadNo'=>$obj[0]->downloadNo+1)) - ->condition('nid', $node->nid)->execute(); - }else{ - db_insert('arxiv_downNo')->fields(array ('nid'=>$node->nid,'downloadNo'=>1))->execute(); - } - - //download - foreach (field_info_instances('node', $bundle) as $instance) { - if($instance['widget']['module']=='arxiv'){ - if ($node->{$instance['field_name']}['und'][0]['pdfUrl'] != ''&& $type=='pdf') { - $url=$node->{$instance['field_name']}['und'][0]['pdfUrl']; - header( "Location: $url" ); + if (empty($node)) { + global $base_url; + drupal_set_message("Paper not found, are you maybe in PREVIEW mode?", 'error'); + drupal_goto($base_url); + } + $langcode = $GLOBALS['language_content']->language; + node_build_content($node, 'full', $langcode); + list(, , $bundle) = entity_extract_ids('node', $node); + //increase download number + $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) + ->condition('m.nid', $node->nid)->execute()->fetchAll(); + if($obj){ + db_update('arxiv_downNo')->fields(array ('downloadNo'=>$obj[0]->downloadNo+1)) + ->condition('nid', $node->nid)->execute(); + }else{ + db_insert('arxiv_downNo')->fields(array ('nid'=>$node->nid,'downloadNo'=>1))->execute(); + } + + //download + + foreach (field_info_instances('node', $bundle) as $instance) { + if($instance['widget']['module']=='arxiv'){ + if ($node->{$instance['field_name']}['und'][0]['pdfUrl'] != ''&& $type=='pdf') { + $url=$node->{$instance['field_name']}['und'][0]['pdfUrl']; + header( "Location: $url" ); // return $node->{$instance['field_name']}['und'][0]['pdfUrl']; - } - if ($node->{$instance['field_name']}['und'][0]['psUrl'] != ''&&$type=='ps') { - $url=$node->{$instance['field_name']}['und'][0]['psUrl']; - header( "Location: $url" ); - //return $node->{$instance['field_name']}['und'][0]['psUrl']; - } - if ($node->{$instance['field_name']}['und'][0]['otherUrl'] != ''&&$type=='other') { - $url=$node->{$instance['field_name']}['und'][0]['otherUrl']; - header( "Location: $url" ); - } - }else if($instance['field_name']=='field_upload'){ - if ($node->{$instance['field_name']}['und'][0]['filename'] != '') { - $url = file_create_url(http://github.com/$node-%3E%7B$instance['field_name']%7D['und'][0]['uri']); - header( "Location: $url" ); - } - } - } - -} \ No newline at end of file + } + if ($node->{$instance['field_name']}['und'][0]['psUrl'] != ''&&$type=='ps') { + $url=$node->{$instance['field_name']}['und'][0]['psUrl']; + header( "Location: $url" ); + //return $node->{$instance['field_name']}['und'][0]['psUrl']; + } + if ($node->{$instance['field_name']}['und'][0]['otherUrl'] != ''&&$type=='other') { + $url=$node->{$instance['field_name']}['und'][0]['otherUrl']; + header( "Location: $url" ); + } + }else if($instance['field_name']=='field_upload'){ + if ($node->{$instance['field_name']}['und'][0]['filename'] != '') { + $url = file_create_url(http://github.com/$node-%3E%7B$instance['field_name']%7D['und'][0]['uri']); + header( "Location: $url" ); + } + } + } +} + From 3a80b7bde04d70696a4ac5ab425ee0ac42b47c66 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 May 2013 17:31:14 +0200 Subject: [PATCH 09/14] add t function for warning message --- arxiv.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arxiv.module b/arxiv.module index 1d4fa08..e61cb89 100755 --- a/arxiv.module +++ b/arxiv.module @@ -396,7 +396,8 @@ function paper_download($nid,$type){ $node = node_load($nid); if (empty($node)) { global $base_url; - drupal_set_message("Paper not found, are you maybe in PREVIEW mode?", 'error'); + $text = t("Paper not found, are you maybe in PREVIEW mode?"); + drupal_set_message($text,"warning"); drupal_goto($base_url); } $langcode = $GLOBALS['language_content']->language; From b131478023a6233241a3a1d4e0c021f12fb2b69c Mon Sep 17 00:00:00 2001 From: 87 Date: Wed, 5 Jun 2013 14:59:25 +0200 Subject: [PATCH 10/14] check coder module --- arxiv.install | 16 +- arxiv.module | 761 +++++++++++++++++++++++++------------------------- 2 files changed, 389 insertions(+), 388 deletions(-) diff --git a/arxiv.install b/arxiv.install index a6f919a..9ced7bd 100644 --- a/arxiv.install +++ b/arxiv.install @@ -20,13 +20,13 @@ function arxiv_schema() { 'not null' => TRUE, 'description' => 'node ID.', ), - 'downloadNo' => array ( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'download number' - ), + 'downloadNo' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'download number' + ), ), 'primary key' => array('nid'), 'indexes' => array( @@ -44,4 +44,4 @@ function arxiv_uninstall() { $del = db_delete('variable') ->condition('name', 'arxiv_%', 'LIKE') ->execute(); -} \ No newline at end of file +} diff --git a/arxiv.module b/arxiv.module index e61cb89..d806945 100755 --- a/arxiv.module +++ b/arxiv.module @@ -1,379 +1,378 @@ - array ( - 'label' => t('Arxiv'), - 'description' => 'This field gets a paper from arxiv.org', - 'default_widget' => 'text_field', - 'default_formatter' => 'arxiv_default', - 'settings' => array ( - 'max_length' => 9 - ), - ), - ); + array( + 'label' => t('Arxiv'), + 'description' => 'This field gets a paper from arxiv.org', + 'default_widget' => 'text_field', + 'default_formatter' => 'arxiv_default', + 'settings' => array( + 'max_length' => 9 + ), + ), + ); } function arxiv_field_schema($field) { - if ($field['type'] == 'arxiv') { - $schema = array ( - 'columns' => array ( - 'serialNo' => array ( - 'type' => 'varchar', - 'length' => 20, - 'default' => '' - ), - 'authors' => array ( - 'type' => 'varchar', - 'length' => 100, - 'default' => '' - ), - 'abstract' => array ( - 'type' => 'varchar', - 'length' => 2000, - 'default' => '' - ), - 'pdfUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'psUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'otherUrl' => array ( - 'type' => 'varchar', - 'length' => 300, - 'default' => '' - ), - 'downloadNo' => array ( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'download number' - ), - - - ), - 'indexs' => array ( - 'serialNo' - ), - - - ); - return $schema; - } + if ($field['type'] == 'arxiv') { + $schema = array( + 'columns' => array( + 'serialNo' => array( + 'type' => 'varchar', + 'length' => 20, + 'default' => '' + ), + 'authors' => array( + 'type' => 'varchar', + 'length' => 100, + 'default' => '' + ), + 'abstract' => array( + 'type' => 'varchar', + 'length' => 2000, + 'default' => '' + ), + 'pdfUrl' => array( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'psUrl' => array( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'otherUrl' => array( + 'type' => 'varchar', + 'length' => 300, + 'default' => '' + ), + 'downloadNo' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'download number' + ), + + + ), + 'indexs' => array( + 'serialNo' + ), + + + ); + return $schema; + } } function _arxiv_field_validate($element, & $form_state) { - if ($form_state['complete form']['#form_id'] == 'field_ui_field_edit_form') { - return; - } - $values = $form_state['values']; - $language = $values['language']; - $field_name = $element['#field_name']; - foreach ($values[$field_name][$language] as $delta => $item) { - if (!empty ($item['text_field_wrapper']['arxivinfo'])) { - $obj = db_select('field_data_' . $field_name, 'm')->fields('m', array ( - 'entity_type', - 'entity_id' - ))->condition('m.' . - $field_name . '_serialNo', $item['text_field_wrapper']['arxivinfo'])->condition('m.deleted', 0)->execute()->fetchAll(); - if ($obj) - form_set_error($field_name, t('The paper you submitted already exists. Click here to view it.')); - else { - include_once (ARXIV_PATH . '/parser/BrowserEmulator.php'); - $html = BrowserEmulator :: openArxiv($item['text_field_wrapper']['arxivinfo']); - if (!$html) { - form_set_error($field_name, t('Could not connect to the server. Please try again later.')); - return; - } - - // serial id doesn't exist - if ($html == '' || strpos($html, "Paper identifier '" . $item['text_field_wrapper']['arxivinfo'] . "' not recognized") !== false ||strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== false || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== false) { - form_set_error($field_name, t('The paper you submitted does not exist.')); - return; - } - } - } - //print_r($item['text_field_wrapper']['arxivinfo']); - $new_value = arxiv_get_paper($item['text_field_wrapper']['arxivinfo']); - form_set_value($element, $new_value, $form_state); - } + if ($form_state['complete form']['#form_id'] == 'field_ui_field_edit_form') { + return; + } + $values = $form_state['values']; + $language = $values['language']; + $field_name = $element['#field_name']; + foreach ($values[$field_name][$language] as $delta => $item) { + if (!empty ($item['text_field_wrapper']['arxivinfo'])) { + $obj = db_select('field_data_' . $field_name, 'm')->fields('m', array( + 'entity_type', + 'entity_id' + ))->condition('m.' . + $field_name . '_serialNo', $item['text_field_wrapper']['arxivinfo'])->condition('m.deleted', 0)->execute()->fetchAll(); + if ($obj) + form_set_error($field_name, t('The paper you submitted already exists. Click here to view it.')); + else { + include_once(ARXIV_PATH . '/parser/BrowserEmulator.php'); + $html = BrowserEmulator :: openArxiv($item['text_field_wrapper']['arxivinfo']); + if (!$html) { + form_set_error($field_name, t('Could not connect to the server. Please try again later.')); + return; + } + + // serial id doesn't exist + if ($html == '' || strpos($html, "Paper identifier '" . $item['text_field_wrapper']['arxivinfo'] . "' not recognized") !== FALSE ||strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " not recognized") !== FALSE || strpos($html, "Paper " . $item['text_field_wrapper']['arxivinfo'] . " doesn't exist") !== FALSE) { + form_set_error($field_name, t('The paper you submitted does not exist.')); + return; + } + } + } + //print_r($item['text_field_wrapper']['arxivinfo']); + $new_value = arxiv_get_paper($item['text_field_wrapper']['arxivinfo']); + form_set_value($element, $new_value, $form_state); + } } function arxiv_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { - list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); - $node=node_load($id,$vid); - foreach($items as $delta=>$item){ - $node->title=$item['title']; - } + list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); + $node = node_load($id, $vid); + foreach ($items as $delta => $item) { + $node->title=$item['title']; + } - node_save($node); + node_save($node); } function arxiv_node_validate($node, $form, &$form_state) { - foreach($form_state['field'] as $type=>$name){ - if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - if(isset($form_state['values']['field_serial_no'])){ - $form_state['values']['title']= $form_state['values']['field_serial_no']['und'][0]['title']; - } - break; - } - } + foreach ( $form_state['field'] as $type => $name) { + if ($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv') { + if ( isset($form_state['values']['field_serial_no'])) { + $form_state['values']['title']= $form_state['values']['field_serial_no']['und'][0]['title']; + } + break; + } + } } function arxiv_field_widget_info() { - return array ( - 'text_field' => array ( - 'label' => t('Text field'), - 'desscription' => t('Allow the user to enter arxiv serial No.'), - 'field types' => array ( - 'arxiv' - ), - 'settings' => array ( - 'number' => '' - ), - 'behaviors' => array ( - 'multiple values' => FIELD_BEHAVIOR_DEFAULT, - 'default value' => FIELD_BEHAVIOR_CUSTOM, + return array( + 'text_field' => array( + 'label' => t('Text field'), + 'desscription' => t('Allow the user to enter arxiv serial No.'), + 'field types' => array( + 'arxiv' + ), + 'settings' => array( + 'number' => '' + ), + 'behaviors' => array( + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + 'default value' => FIELD_BEHAVIOR_CUSTOM, - ), + ), - ), + ), - ); + ); } function arxiv_field_widget_settings_form($field, $instance) { - $form = array (); - $widget = $instance['widget']; - $settings = $widget['settings']; - //if ($widget['type'] == 'text_field') { - // $form['number'] = array ( - // '#type' => 'textfield', - // '#title' => t('Serial No'), - // '#required' => TRUE, - // '#default_value' => $settings['number'], - - - // ); - //} - return $form; + $form = array(); + $widget = $instance['widget']; + $settings = $widget['settings']; + //if ($widget['type'] == 'text_field') { + // $form['number'] = array ( + // '#type' => 'textfield', + // '#title' => t('Serial No'), + // '#required' => TRUE, + // '#default_value' => $settings['number'], + + + // ); + //} + return $form; } function arxiv_field_widget_form(& $form, & $form_state, $field, $instance, $langcode, $items, $delta, $element) { - $base = $element; - - if ($instance['widget']['type'] == 'text_field') { - $element['#element_validate'] = array ( - '_arxiv_field_validate' - ); - $default = NULL; - if (isset ($items[$delta])) { - $item = $items[$delta]; - $default = $item['serialNo']; - } - $element['text_field_wrapper']['#theme'] = 'text_field_wrapper'; - $element['text_field_wrapper']['arxivinfo'] = array ( - '#type' => 'textfield', - '#default_value' => $default, - '#number' => $instance['widget']['settings']['number'], - - - ) + $base; - } - return $element; + $base = $element; + + if ($instance['widget']['type'] == 'text_field') { + $element['#element_validate'] = array( + '_arxiv_field_validate' + ); + $default = NULL; + if (isset ($items[$delta])) { + $item = $items[$delta]; + $default = $item['serialNo']; + } + $element['text_field_wrapper']['#theme'] = 'text_field_wrapper'; + $element['text_field_wrapper']['arxivinfo'] = array( + '#type' => 'textfield', + '#default_value' => $default, + '#number' => $instance['widget']['settings']['number'], + + + ) + $base; + } + return $element; } function arxiv_field_formatter_info() { - return array ( - 'arxiv_default' => array ( - 'label' => t('Default'), - 'field types' => array ( - 'arxiv' - ), + return array( + 'arxiv_default' => array( + 'label' => t('Default'), + 'field types' => array( + 'arxiv' + ), - ), - 'arxiv_download' => array ( - 'label' => t('Plain text with download link only'), - 'field types' => array ( - 'arxiv' - ), + ), + 'arxiv_download' => array( + 'label' => t('Plain text with download link only'), + 'field types' => array( + 'arxiv' + ), - ), - 'arxiv_abstract' => array ( - 'label' => t('Plain text with abstract info only'), - 'field types' => array ( - 'arxiv' - ), + ), + 'arxiv_abstract' => array( + 'label' => t('Plain text with abstract info only'), + 'field types' => array( + 'arxiv' + ), - ), + ), - ); + ); } function arxiv_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array (); - $statistics = statistics_get($entity->nid); - $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) - ->condition('m.nid', $entity->nid)->execute()->fetchAll(); - if($obj){ - $info = ' ('.$statistics['totalcount'].' views, '.$obj[0]->downloadNo.' download, '.$entity->comment_count.' comments)'; - }elseif(isset($entity->comment_count)){ - $info = ' ('.$statistics['totalcount'].' views, 0 download, '.$entity->comment_count.' comments)'; - }else{ - $info = ' '; - } - - switch ($display['type']) { - case 'arxiv_default' : - foreach ($items as $delta => $item) { - $output = '

' . $item['abstract'] . '

'; - if ($item['pdfUrl'] != '') { - $output .= 'pdf '; - } - if ($item['psUrl'] != '') { - $output .= 'ps '; - } - if ($item['otherUrl'] != '') { - $output .= 'other '; - } - $output .= $info.'

'; - $element[$delta] = array ( - '#markup' => $output - ); - } - - break; - - case 'arxiv_download' : - foreach ($items as $delta => $item) { - $output = '

'; - if ($item['pdfUrl'] != '') { - $output .= 'pdf '; - } - if ($item['psUrl'] != '') { - $output .= 'ps '; - } - if ($item['otherUrl'] != '') { - $output .= 'other '; - } - $output .= $info.'

'; - $element[$delta] = array ( - '#markup' => $output - ); - } - break; - - case 'arxiv_abstract' : - foreach ($items as $delta => $item) { - $output = '

' . $item['abstract'] . '

'; - $element[$delta] = array ( - '#markup' => $output - ); - } - - break; - } - - return $element; + $element = array(); + $statistics = statistics_get($entity->nid); + $obj = db_select('arxiv_downNo', 'm')->fields('m', array('downloadNo')) + ->condition('m.nid', $entity->nid)->execute()->fetchAll(); + if ($obj) { + $info = ' (' . $statistics['totalcount'] . ' views, ' . $obj[0]->downloadNo . ' download, ' . $entity->comment_count . ' comments)'; + } +elseif (isset($entity->comment_count)) { + $info = ' (' . $statistics['totalcount'] . ' views, 0 download, ' . $entity->comment_count . ' comments)'; + } +else{ + $info = ' '; + } + + switch ($display['type']) { + case 'arxiv_default' : + foreach ($items as $delta => $item) { + $output = '

' . $item['abstract'] . '

'; + if ($item['pdfUrl'] != '') { + $output .= 'pdf '; + } + if ($item['psUrl'] != '') { + $output .= 'ps '; + } + if ($item['otherUrl'] != '') { + $output .= 'other '; + } + $output .= $info . '

'; + $element[$delta] = array( + '#markup' => $output + ); + } + + break; + + case 'arxiv_download' : + foreach ($items as $delta => $item) { + $output = '

'; + if ($item['pdfUrl'] != '') { + $output .= 'pdf '; + } + if ($item['psUrl'] != '') { + $output .= 'ps '; + } + if ($item['otherUrl'] != '') { + $output .= 'other '; + } + $output .= $info . '

'; + $element[$delta] = array( + '#markup' => $output + ); + } + break; + + case 'arxiv_abstract' : + foreach ($items as $delta => $item) { + $output = '

' . $item['abstract'] . '

'; + $element[$delta] = array( + '#markup' => $output + ); + } + + break; + } + + return $element; } function arxiv_field_is_empty($item, $field) { - if ($field['type'] == 'arxiv') { - if (!isset ($item['serialNo']) || $item['serialNo'] === '') { - return true; - } - } - return FALSE; + if ($field['type'] == 'arxiv') { + if (!isset ($item['serialNo']) || $item['serialNo'] === '') { + return TRUE; + } + } + return FALSE; } function arxiv_get_paper($serialNo) { - include_once (ARXIV_PATH . '/parser/HtmlDom.php'); - include_once (ARXIV_PATH . '/parser/BrowserEmulator.php'); - $html = BrowserEmulator :: openArxiv($serialNo); - $item = array ( - 'serialNo' => $serialNo - ); - $dom = str_get_html($html); - $fulltext = $dom->find('.full-text'); - $lis = $fulltext[0]->find('li'); - $item['otherUrl']='';$item['psUrl']='';$item['pdfUrl'] =''; - foreach ($lis as $li) { - if (strpos($li, 'PDF') !== false) { - $item['pdfUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; - } - if (strpos($li, 'PostScript') !== false) { - $item['psUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; - } - if (strpos($li, 'Other') !== false) { - $item['OtherUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; - } - } - - // 2) title - $titles = $dom->find('.title'); - $arxivTitle = $titles[0]->innerText(); - $arxivTitle = substr($arxivTitle, strpos($arxivTitle, '') + 7); // 7 is the length of '' - $arxivTitle = html_entity_decode($arxivTitle, ENT_QUOTES, 'utf-8'); - - // 3) authors - $authors = $dom->find('.authors'); - $authors = $authors[0]->children; - $arxivAuthor = ''; - for ($i = 1; $i < sizeof($authors) - 1; $i++) - $arxivAuthor .= $authors[$i]->innerText() . ', '; - $arxivAuthor .= $authors[sizeof($authors) - 1]->innerText(); - $arxivAuthor = html_entity_decode($arxivAuthor, ENT_QUOTES, 'utf-8'); - - // 4) abstract - $abstracts = $dom->find('.abstract'); - foreach ($abstracts[0]->find('a') as $a) { - $a->outertext = $a->innertext; - } - $arxivAbstract = $abstracts[0]->innerText(); - $arxivAbstract = substr($arxivAbstract, strpos($arxivAbstract, '') + 7); // 7 is the length of '' - $arxivAbstract = html_entity_decode($arxivAbstract, ENT_QUOTES, 'utf-8'); - - if (strlen($arxivAuthor) > 100) { - $arxivAuthor=substr($arxivAuthor,0,95).'...'; - } - if (strlen($arxivAbstract) > 2000) { - $arxivAbstract=substr($arxivAbstract,0,1995).'...'; - } - if (strlen($arxivTitle) > 255) { - $arxivTitle=substr($arxivTitle,0,250).'...'; - } - - - $item['title'] = $arxivTitle; - $item['authors'] = $arxivAuthor; - $item['abstract'] = $arxivAbstract; - $item['downloadNo'] = 0; - return $item; + include_once(ARXIV_PATH . '/parser/HtmlDom.php'); + include_once(ARXIV_PATH . '/parser/BrowserEmulator.php'); + $html = BrowserEmulator :: openArxiv($serialNo); + $item = array( + 'serialNo' => $serialNo + ); + $dom = str_get_html($html); + $fulltext = $dom->find('.full-text'); + $lis = $fulltext[0]->find('li'); + $item['otherUrl']='';$item['psUrl']='';$item['pdfUrl'] =''; + foreach ($lis as $li) { + if (strpos($li, 'PDF') !== FALSE) { + $item['pdfUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; + } + if (strpos($li, 'PostScript') !== FALSE) { + $item['psUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; + } + if (strpos($li, 'Other') !== FALSE) { + $item['OtherUrl'] = 'http://arxiv.org/' . $li->children[0]->attr['href']; + } + } + + // 2) title + $titles = $dom->find('.title'); + $arxivTitle = $titles[0]->innerText(); + $arxivTitle = substr($arxivTitle, strpos($arxivTitle, '') + 7); // 7 is the length of '' + $arxivTitle = html_entity_decode($arxivTitle, ENT_QUOTES, 'utf-8'); + + // 3) authors + $authors = $dom->find('.authors'); + $authors = $authors[0]->children; + $arxivAuthor = ''; + for ($i = 1; $i < sizeof($authors) - 1; $i++) + $arxivAuthor .= $authors[$i]->innerText() . ', '; + $arxivAuthor .= $authors[sizeof($authors) - 1]->innerText(); + $arxivAuthor = html_entity_decode($arxivAuthor, ENT_QUOTES, 'utf-8'); + + // 4) abstract + $abstracts = $dom->find('.abstract'); + foreach ($abstracts[0]->find('a') as $a) { + $a->outertext = $a->innertext; + } + $arxivAbstract = $abstracts[0]->innerText(); + $arxivAbstract = substr($arxivAbstract, strpos($arxivAbstract, '') + 7); // 7 is the length of '' + $arxivAbstract = html_entity_decode($arxivAbstract, ENT_QUOTES, 'utf-8'); + + if (strlen($arxivAuthor) > 100) { + $arxivAuthor = substr($arxivAuthor,0,95) . '...'; + } + if (strlen($arxivAbstract) > 2000) { + $arxivAbstract = substr($arxivAbstract,0,1995) . '...'; + } + if (strlen($arxivTitle) > 255) { + $arxivTitle = substr($arxivTitle,0,250) . '...'; + } + + + $item['title'] = $arxivTitle; + $item['authors'] = $arxivAuthor; + $item['abstract'] = $arxivAbstract; + $item['downloadNo'] = 0; + return $item; } function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { - foreach($form_state['field'] as $type=>$name){ - if($form_state['field'][$type]['und']['instance']['widget']['module']=='arxiv'){ - $form['title']['#value']='null'; - $form['title']['#type'] = 'value'; - $form['title']['#required'] = FALSE; - break; - } - } + foreach ($form_state['field'] as $type => $name) { + if ($form_state['field'][$type]['und']['instance']['widget']['module'] == 'arxiv') { + $form['title']['#value']='null'; + $form['title']['#type'] = 'value'; + $form['title']['#required'] = FALSE; + break; + } + } } @@ -381,62 +380,64 @@ function arxiv_form_node_form_alter(&$form, &$form_state, $form_id) { * Implementation of hook_menu(). */ function arxiv_menu() { - $items['paper/download/%/%'] = array( - // 'page callback' => 'postform_overlay', - 'title'=>'Download the paper', - 'page callback' => 'paper_download', - 'page arguments' => array(2,3), - 'access callback' => TRUE, - 'type' => MENU_CALLBACK - ); - return $items; + $items['paper/download/%/%'] = array( + // 'page callback' => 'postform_overlay', + 'title' => 'Download the paper', + 'page callback' => 'paper_download', + 'page arguments' => array(2, 3), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK + ); + return $items; } -function paper_download($nid,$type){ - $node = node_load($nid); - if (empty($node)) { - global $base_url; - $text = t("Paper not found, are you maybe in PREVIEW mode?"); - drupal_set_message($text,"warning"); - drupal_goto($base_url); - } - $langcode = $GLOBALS['language_content']->language; - node_build_content($node, 'full', $langcode); - list(, , $bundle) = entity_extract_ids('node', $node); - //increase download number - $obj = db_select('arxiv_downNo', 'm')->fields('m', array ('downloadNo')) - ->condition('m.nid', $node->nid)->execute()->fetchAll(); - if($obj){ - db_update('arxiv_downNo')->fields(array ('downloadNo'=>$obj[0]->downloadNo+1)) - ->condition('nid', $node->nid)->execute(); - }else{ - db_insert('arxiv_downNo')->fields(array ('nid'=>$node->nid,'downloadNo'=>1))->execute(); - } - - //download - - foreach (field_info_instances('node', $bundle) as $instance) { - if($instance['widget']['module']=='arxiv'){ - if ($node->{$instance['field_name']}['und'][0]['pdfUrl'] != ''&& $type=='pdf') { - $url=$node->{$instance['field_name']}['und'][0]['pdfUrl']; - header( "Location: $url" ); - // return $node->{$instance['field_name']}['und'][0]['pdfUrl']; - } - if ($node->{$instance['field_name']}['und'][0]['psUrl'] != ''&&$type=='ps') { - $url=$node->{$instance['field_name']}['und'][0]['psUrl']; - header( "Location: $url" ); - //return $node->{$instance['field_name']}['und'][0]['psUrl']; - } - if ($node->{$instance['field_name']}['und'][0]['otherUrl'] != ''&&$type=='other') { - $url=$node->{$instance['field_name']}['und'][0]['otherUrl']; - header( "Location: $url" ); - } - }else if($instance['field_name']=='field_upload'){ - if ($node->{$instance['field_name']}['und'][0]['filename'] != '') { - $url = file_create_url(http://github.com/$node-%3E%7B$instance['field_name']%7D['und'][0]['uri']); - header( "Location: $url" ); - } - } - } +function paper_download($nid, $type) { + $node = node_load($nid); + if (empty($node)) { + global $base_url; + $text = t("Paper not found, are you maybe in PREVIEW mode?"); + drupal_set_message($text, "warning"); + drupal_goto($base_url); + } + $langcode = $GLOBALS['language_content']->language; + node_build_content($node, 'full', $langcode); + list(, , $bundle) = entity_extract_ids('node', $node); + //increase download number + $obj = db_select('arxiv_downNo', 'm')->fields('m', array('downloadNo')) + ->condition('m.nid', $node->nid)->execute()->fetchAll(); + if ($obj) { + db_update('arxiv_downNo')->fields(array('downloadNo' => $obj[0]->downloadNo+1)) + ->condition('nid', $node->nid)->execute(); + } +else{ + db_insert('arxiv_downNo')->fields(array('nid' => $node->nid, 'downloadNo' => 1))->execute(); + } + + //download + + foreach (field_info_instances('node', $bundle) as $instance) { + if ($instance['widget']['module']=='arxiv') { + if ($node->{$instance['field_name']}['und'][0]['pdfUrl'] != ''&& $type=='pdf') { + $url=$node->{$instance['field_name']}['und'][0]['pdfUrl']; + header( "Location: $url" ); + // return $node->{$instance['field_name']}['und'][0]['pdfUrl']; + } + if ($node->{$instance['field_name']}['und'][0]['psUrl'] != ''&&$type=='ps') { + $url=$node->{$instance['field_name']}['und'][0]['psUrl']; + header( "Location: $url" ); + //return $node->{$instance['field_name']}['und'][0]['psUrl']; + } + if ($node->{$instance['field_name']}['und'][0]['otherUrl'] != ''&&$type=='other') { + $url=$node->{$instance['field_name']}['und'][0]['otherUrl']; + header( "Location: $url" ); + } + } +else if ($instance['field_name']=='field_upload') { + if ($node->{$instance['field_name']}['und'][0]['filename'] != '') { + $url = file_create_url(http://github.com/$node-%3E%7B$instance['field_name']%7D['und'][0]['uri']); + header( "Location: $url" ); + } + } + } } From 703b64bbbb3f08a9250d779012ad551a7dcc1c7f Mon Sep 17 00:00:00 2001 From: drozas Date: Mon, 15 Jul 2013 10:04:44 +0100 Subject: [PATCH 11/14] Removing the whitespace and close tag for php --- arxiv.info | 1 - arxiv.module | 2 +- parser/HtmlDom.php | 247 ++++++++++++++++++++++----------------------- 3 files changed, 124 insertions(+), 126 deletions(-) diff --git a/arxiv.info b/arxiv.info index b85666a..0ffaf5f 100755 --- a/arxiv.info +++ b/arxiv.info @@ -1,4 +1,3 @@ -; $Id: arxiv.info,v 1.0 $ name = Arxiv description = Get paper from arxiv.org. core = 7.x diff --git a/arxiv.module b/arxiv.module index d806945..1511bc6 100755 --- a/arxiv.module +++ b/arxiv.module @@ -1,4 +1,4 @@ - array( 'label' => t('Arxiv'), diff --git a/parser/HtmlDom.php b/parser/HtmlDom.php index 74e3022..067fbfe 100755 --- a/parser/HtmlDom.php +++ b/parser/HtmlDom.php @@ -1,15 +1,15 @@ - Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/) - Contributions by: - Yousuke Kumakura (Attribute filters) - Vadim Voituk (Negative indexes supports of "find" method) - Antcs (Constructor with automatically load contents either text or file/url) - Licensed under The MIT License - Redistributions of files must retain the above copyright notice. +/******************************************************************************* + Version: 1.11 ($Rev: 175 $) + Website: http://sourceforge.net/projects/simplehtmldom/ + Author: S.C. Chen + Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/) + Contributions by: + Yousuke Kumakura (Attribute filters) + Vadim Voituk (Negative indexes supports of "find" method) + Antcs (Constructor with automatically load contents either text or file/url) + Licensed under The MIT License + Redistributions of files must retain the above copyright notice. *******************************************************************************/ define ( 'HDOM_TYPE_ELEMENT', 1 ); @@ -30,9 +30,9 @@ define ( 'HDOM_INFO_OUTER', 6 ); define ( 'HDOM_INFO_ENDSPACE', 7 ); -// helper functions -// ----------------------------------------------------------------------------- -// get html dom form file +// helper functions +// ----------------------------------------------------------------------------- +// get html dom form file function file_get_html() { $dom = new HtmlDom ( ); $args = func_get_args (); @@ -40,14 +40,14 @@ function file_get_html() { return $dom; } -// get html dom form string +// get html dom form string function str_get_html($str, $lowercase = true) { $dom = new HtmlDom ( ); $dom->load ( $str, $lowercase ); return $dom; } -// dump html dom tree +// dump html dom tree function dump_html_tree($node, $show_attr = true, $deep = 0) { $lead = str_repeat ( ' ', $deep ); echo $lead . $node->tag; @@ -63,7 +63,7 @@ function dump_html_tree($node, $show_attr = true, $deep = 0) { dump_html_tree ( $c, $show_attr, $deep + 1 ); } -// get dom form file (deprecated) +// get dom form file (deprecated) function file_get_dom() { $dom = new HtmlDom ( ); $args = func_get_args (); @@ -71,15 +71,15 @@ function file_get_dom() { return $dom; } -// get dom form string (deprecated) +// get dom form string (deprecated) function str_get_dom($str, $lowercase = true) { $dom = new HtmlDom ( ); $dom->load ( $str, $lowercase ); return $dom; } -// simple html dom node -// ----------------------------------------------------------------------------- +// simple html dom node +// ----------------------------------------------------------------------------- class HtmlDomNode { public $nodetype = HDOM_TYPE_TEXT; public $tag = 'text'; @@ -103,7 +103,7 @@ function __toString() { return $this->outertext (); } - // clean up memory due to php5 circular references memory leak... + // clean up memory due to php5 circular references memory leak... function clear() { $this->dom = null; $this->nodes = null; @@ -111,17 +111,17 @@ function clear() { $this->children = null; } - // dump node's tree + // dump node's tree function dump($show_attr = true) { dump_html_tree ( $this, $show_attr ); } - // returns the parent of node + // returns the parent of node function parent() { return $this->parent; } - // returns children of node + // returns children of node function children($idx = -1) { if ($idx === - 1) return $this->children; @@ -130,21 +130,21 @@ function children($idx = -1) { return null; } - // returns the first child of node + // returns the first child of node function first_child() { if (count ( $this->children ) > 0) return $this->children [0]; return null; } - // returns the last child of node + // returns the last child of node function last_child() { if (($count = count ( $this->children )) > 0) return $this->children [$count - 1]; return null; } - // returns the next sibling of node + // returns the next sibling of node function next_sibling() { if ($this->parent === null) return null; @@ -157,7 +157,7 @@ function next_sibling() { return $this->parent->children [$idx]; } - // returns the previous sibling of node + // returns the previous sibling of node function prev_sibling() { if ($this->parent === null) return null; @@ -170,7 +170,7 @@ function prev_sibling() { return $this->parent->children [$idx]; } - // get dom node's inner html + // get dom node's inner html function innertext() { if (isset ( $this->_ [HDOM_INFO_INNER] )) return $this->_ [HDOM_INFO_INNER]; @@ -183,12 +183,12 @@ function innertext() { return $ret; } - // get dom node's outer text (with tag) + // get dom node's outer text (with tag) function outertext() { if ($this->tag === 'root') return $this->innertext (); - // trigger callback + // trigger callback if ($this->dom->callback !== null) call_user_func_array ( $this->dom->callback, array ($this ) ); @@ -197,10 +197,10 @@ function outertext() { if (isset ( $this->_ [HDOM_INFO_TEXT] )) return $this->dom->restore_noise ( $this->_ [HDOM_INFO_TEXT] ); - // render begin tag + // render begin tag $ret = $this->dom->nodes [$this->_ [HDOM_INFO_BEGIN]]->makeup (); - // render inner text + // render inner text if (isset ( $this->_ [HDOM_INFO_INNER] )) $ret .= $this->_ [HDOM_INFO_INNER]; else { @@ -208,13 +208,13 @@ function outertext() { $ret .= $n->outertext (); } - // render end tag + // render end tag if (isset ( $this->_ [HDOM_INFO_END] ) && $this->_ [HDOM_INFO_END] != 0) $ret .= 'tag . '>'; return $ret; } - // get dom node's plain text + // get dom node's plain text function text() { if (isset ( $this->_ [HDOM_INFO_INNER] )) return $this->_ [HDOM_INFO_INNER]; @@ -244,9 +244,9 @@ function xmltext() { return $ret; } - // build node's text with tag + // build node's text with tag function makeup() { - // text, comment, unknown + // text, comment, unknown if (isset ( $this->_ [HDOM_INFO_TEXT] )) return $this->dom->restore_noise ( $this->_ [HDOM_INFO_TEXT] ); @@ -256,12 +256,12 @@ function makeup() { foreach ( $this->attr as $key => $val ) { ++ $i; - // skip removed attribute + // skip removed attribute if ($val === null || $val === false) continue; $ret .= $this->_ [HDOM_INFO_SPACE] [$i] [0]; - //no value attr: nowrap, checked selected... + //no value attr: nowrap, checked selected... if ($val === true) $ret .= $key; else { @@ -282,14 +282,14 @@ function makeup() { return $ret . $this->_ [HDOM_INFO_ENDSPACE] . '>'; } - // find elements by css selector + // find elements by css selector function find($selector, $idx = null) { $selectors = $this->parse_selector ( $selector ); if (($count = count ( $selectors )) === 0) return array (); $found_keys = array (); - // find each selector + // find each selector for($c = 0; $c < $count; ++ $c) { if (($levle = count ( $selectors [0] )) === 0) return array (); @@ -298,7 +298,7 @@ function find($selector, $idx = null) { $head = array ($this->_ [HDOM_INFO_BEGIN] => 1 ); - // handle descendant selectors, no recursive! + // handle descendant selectors, no recursive! for($l = 0; $l < $levle; ++ $l) { $ret = array (); foreach ( $head as $k => $v ) { @@ -314,14 +314,14 @@ function find($selector, $idx = null) { } } - // sort keys + // sort keys ksort ( $found_keys ); $found = array (); foreach ( $found_keys as $k => $v ) $found [] = $this->dom->nodes [$k]; - // return nth-element or array + // return nth-element or array if (is_null ( $idx )) return $found; else if ($idx < 0) @@ -329,11 +329,11 @@ function find($selector, $idx = null) { return (isset ( $found [$idx] )) ? $found [$idx] : null; } - // seek for given conditions + // seek for given conditions protected function seek($selector, &$ret) { list ( $tag, $key, $val, $exp, $no_key ) = $selector; - // xpath index + // xpath index if ($tag && $key && is_numeric ( $key )) { $count = 0; foreach ( $this->children as $c ) { @@ -367,11 +367,11 @@ protected function seek($selector, &$ret) { continue; } - // compare tag + // compare tag if ($tag && $tag != $node->tag && $tag !== '*') { $pass = false; } - // compare key + // compare key if ($pass && $key) { if ($no_key) { if (isset ( $node->attr [$key] )) @@ -379,10 +379,10 @@ protected function seek($selector, &$ret) { } else if (! isset ( $node->attr [$key] )) $pass = false; } - // compare value + // compare value if ($pass && $key && $val && $val !== '*') { $check = $this->match ( $exp, $val, $node->attr [$key] ); - // handle multiple class + // handle multiple class if (! $check && strcasecmp ( $key, 'class' ) === 0) { foreach ( explode ( ' ', $node->attr [$key] ) as $k ) { $check = $this->match ( $exp, $val, $k ); @@ -418,19 +418,19 @@ protected function match($exp, $pattern, $value) { } protected function parse_selector($selector_string) { - // pattern of CSS selectors, modified from mootools + // pattern of CSS selectors, modified from mootools $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; preg_match_all ( $pattern, trim ( $selector_string ) . ' ', $matches, PREG_SET_ORDER ); $selectors = array (); $result = array (); - //print_r($matches); + //print_r($matches); foreach ( $matches as $m ) { $m [0] = trim ( $m [0] ); if ($m [0] === '' || $m [0] === '/' || $m [0] === '//') continue; - // for borwser grnreated xpath + // for borwser grnreated xpath if ($m [1] === 'tbody') continue; @@ -453,12 +453,12 @@ protected function parse_selector($selector_string) { $val = $m [6]; } - // convert to lowercase + // convert to lowercase if ($this->dom->lowercase) { $tag = strtolower ( $tag ); $key = strtolower ( $key ); } - //elements that do NOT have the specified attribute + //elements that do NOT have the specified attribute if (isset ( $key [0] ) && $key [0] === '!') { $key = substr ( $key, 1 ); $no_key = true; @@ -517,7 +517,7 @@ function __isset($name) { case 'plaintext' : return true; } - //no value attr: nowrap, checked selected... + //no value attr: nowrap, checked selected... return (array_key_exists ( $name, $this->attr )) ? true : isset ( $this->attr [$name] ); } @@ -526,7 +526,7 @@ function __unset($name) { unset ( $this->attr [$name] ); } - // camel naming conventions + // camel naming conventions function getAllAttributes() { return $this->attr; } @@ -574,8 +574,8 @@ function previousSibling() { } } -// simple html dom parser -// ----------------------------------------------------------------------------- +// simple html dom parser +// ----------------------------------------------------------------------------- class HtmlDom { public $root = null; public $nodes = array (); @@ -592,7 +592,7 @@ class HtmlDom { protected $token_equal = ' =/>'; protected $token_slash = " />\r\n\t"; protected $token_attr = ' >'; - // use isset instead of in_array, performance boost about 30%... + // use isset instead of in_array, performance boost about 30%... protected $self_closing_tags = array ('img' => 1, 'br' => 1, 'input' => 1, 'meta' => 1, 'link' => 1, 'hr' => 1, 'base' => 1, 'embed' => 1, 'spacer' => 1 ); protected $block_tags = array ('root' => 1, 'body' => 1, 'form' => 1, 'div' => 1, 'span' => 1, 'table' => 1 ); protected $optional_closing_tags = array ('tr' => array ('tr' => 1, 'td' => 1, 'th' => 1 ), 'th' => array ('th' => 1 ), 'td' => array ('td' => 1 ), 'li' => array ('li' => 1 ), 'dt' => array ('dt' => 1, 'dd' => 1 ), 'dd' => array ('dd' => 1, 'dt' => 1 ), 'dl' => array ('dd' => 1, 'dt' => 1 ), 'p' => array ('p' => 1 ), 'nobr' => array ('nobr' => 1 ) ); @@ -610,51 +610,51 @@ function __destruct() { $this->clear (); } - // load html from string + // load html from string function load($str, $lowercase = true) { - // prepare + // prepare $this->prepare ( $str, $lowercase ); - // strip out comments + // strip out comments $this->remove_noise ( "''is" ); - // strip out cdata + // strip out cdata $this->remove_noise ( "''is", true ); - // strip out