来自uuid hrefs的反向链接 -- 7 领域 和 search 领域 和 i18n-l10n 领域 和 path-aliases 领域 和 entities 领域 drupal 相关 的问题

Backlinks from UUID hrefs


1
vote

问题

中文

目标是Hack Core,以便搜索模块在节点内容中从UUID-Link Hrefs填充 search_node_links 表。

计划方法是修改Core search.module中 search_index 的解析功能

所针对的代码部分是 search.module 的第633-643行。

  if (preg_match($node_regexp, $value, $match)) {   $path = drupal_get_normal_path($match[1]);   if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {     $linknid = $match[1];     if ($linknid > 0) {       $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();       $link = TRUE;       $linktitle = $node->title;     }   } }   

计划是使用 entity_uuid_load 抓取 nid 直接如此:

  if (preg_match($uuid_regexp, $value, $match)) {   $entity = entity_uuid_load('node',$match);   $linknid = key($entity);   if ($linknid > 0) {     $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();     $link = TRUE;     $linktitle = $node->title;   } }   

我已经使用此代码将节点标题与 998887668 设置为包含uuid-href链接的HTML片段;但是,这似乎仍然无法填充 search_node_links 表。

search_index0 正如预期的那样工作,但在这里,它是为了参考 search_index1 进行比较。

  search_index2  

以及以下是uuid链接格式:

  search_index3  

我确信我只是在 search_index4 中看到的东西,这阻止了这一点。任何意见/支持/指针都将非常感谢。

更新:现在发现它不是uuIds导致问题,而是别名路径(可能与全局重定向模块组合)。尝试了以下代码,仍然没有更改 search_index5

  search_index6  

再次,此代码能够提取节点标题,但不是贡献到 search_index7

英文原文

The goal is to hack core so that the search module will populate the search_node_links table from uuid-link hrefs in node content.

Planned approach is to modify the parsing functions of search_index in the core search.module.

The targeted section of code is lines 633-643 of search.module.

if (preg_match($node_regexp, $value, $match)) {   $path = drupal_get_normal_path($match[1]);   if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {     $linknid = $match[1];     if ($linknid > 0) {       $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();       $link = TRUE;       $linktitle = $node->title;     }   } } 

The plan is to use entity_uuid_load to grab the nid directly like so:

if (preg_match($uuid_regexp, $value, $match)) {   $entity = entity_uuid_load('node',$match);   $linknid = key($entity);   if ($linknid > 0) {     $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();     $link = TRUE;     $linktitle = $node->title;   } } 

I've used this code to pull a node title with $value set to an HTML snippet containing a UUID-href link; however, this still seems to fail to populate the search_node_links table.

$uuid_regexp is working as expected, but here it is for reference along with $node_regexp for comparison.

$node_regexp = '@href=[\'"]?(?:' . preg_quote($base_url, '@') . '/|' . preg_quote(base_path(), '@') . ')(?:\?q=)?/?((?![a-z]+:)[^\'">]+)[\'">]@i'; $uuid_regexp = '@href=[\'"]?(?:\[uuid-link:node:)([0-9a-f]{8}-(([0-9a-f]{4}-){3})[0-9a-f]{12})(?:\])(?:[\'">])@i'; 

And here is the UUID link format:

<a href="[uuid-link:node:dc2c18f0-0abb-43b9-899c-f7c0a16934fd]">UUID link</a> 

I'm sure there's something I'm just not seeing in search.module that is preventing this from working as desired. Any comments/support/pointers would be greatly appreciated.

UPDATE: Finding now that it's not UUIDs causing the issue, but aliased paths instead (probably combined with Global Redirect module). Tried the following code instead, still no change in search_node_links.

if (preg_match($node_regexp, $value, $match)) {   $clean_url = preg_split('![(en)|(fr)]/!', $match[1])[1];   $path = drupal_lookup_path("source", $clean_url);   if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {     $linknid = $match[1];     if ($linknid > 0) {       $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();       $link = TRUE;       $linktitle = $node->title;     }   } } 

Again, this code is able to pull a node title but is not contributing to search_node_links.

              
   
   

回答列表

1
 
vote
vote
最佳答案
 
好的,所以这个问题是由我们路径中的语言前缀与别名引起的。 drupal_get_normal_path 正在返回别名而不是节点号,并且当路径有语言前缀时,它返回任何内容。另外发现替代功能 drupal_lookup_path 仅适用于别名路径。最终代码替换 99887663 :的第634行
  $path = drupal_get_normal_path($match[1]);   

变成

  $clean_url = preg_split('!(^[a-z]{2})/!i', $match[1])[1]; if ($non_aliased = drupal_lookup_path("source", $clean_url)) {   $path = $non_aliased; } else {   $path = drupal_get_normal_path($match[1]); }   

search_node_links 表现在正常填充,并"此处的链接" /反向链接视图正常工作。

 

Ok, so this problem was being caused by the language prefix in our paths in conjunction with aliases. drupal_get_normal_path was returning aliases instead of node numbers, and it returned nothing when the path had a language prefix. Also found that the substitute function drupal_lookup_path only works for aliased paths. The final code replaces line 634 of search.module:

$path = drupal_get_normal_path($match[1]); 

becomes

$clean_url = preg_split('!(^[a-z]{2})/!i', $match[1])[1]; if ($non_aliased = drupal_lookup_path("source", $clean_url)) {   $path = $non_aliased; } else {   $path = drupal_get_normal_path($match[1]); } 

The search_node_links table is now being populated properly and the "What links here"/Backlinks views are working correctly.

 
 
0
 
vote

yea抱歉umm the 搜索api 模块无法帮助您索引和搜索自己的内容?

  /**  * Define new types of items that can be searched.  *  * This hook allows modules to define their own item types, for which indexes  * can then be created. (Note that the Search API natively provides support for  * all entity types that specify property information, so they should not be  * added here. You should therefore also not use an existing entity type as the  * identifier of a new item type.)  *  * The main part of defining a new item type is implementing its data source  * controller class, which is responsible for loading items, providing metadata  * and tracking existing items. The module defining a certain item type is also  * responsible for observing creations, updates and deletions of items of that  * type and notifying the Search API of them by calling  * search_api_track_item_insert(), search_api_track_item_change() and  * search_api_track_item_delete(), as appropriate.  * The only other restriction for item types is that they have to have a single  * item ID field, with a scalar value. This is, e.g., used to track indexed  * items.  *  * Note, however, that you can also define item types where some of these  * conditions are not met, as long as you are aware that some functionality of  * the Search API and related modules might then not be available for that type.  *  * @return array  *   An associative array keyed by item type identifier, and containing type  *   information arrays with at least the following keys:  *   - name: A human-readable name for the type.  *   - datasource controller: A class implementing the  *     SearchApiDataSourceControllerInterface interface which will be used as  *     the data source controller for this type.  *   - entity_type: (optional) If the type represents entities, the entity type.  *     This is used by SearchApiAbstractDataSourceController for determining the  *     entity type of items. Other datasource controllers might ignore this.  *   Other, datasource-specific settings might also be placed here. These should  *   be specified with the data source controller in question.  *  * @see hook_search_api_item_type_info_alter()  */ function hook_search_api_item_type_info() { /* ... */ }   
 

yea sorry umm the Search API module can't help you to index and search your own content?

/**  * Define new types of items that can be searched.  *  * This hook allows modules to define their own item types, for which indexes  * can then be created. (Note that the Search API natively provides support for  * all entity types that specify property information, so they should not be  * added here. You should therefore also not use an existing entity type as the  * identifier of a new item type.)  *  * The main part of defining a new item type is implementing its data source  * controller class, which is responsible for loading items, providing metadata  * and tracking existing items. The module defining a certain item type is also  * responsible for observing creations, updates and deletions of items of that  * type and notifying the Search API of them by calling  * search_api_track_item_insert(), search_api_track_item_change() and  * search_api_track_item_delete(), as appropriate.  * The only other restriction for item types is that they have to have a single  * item ID field, with a scalar value. This is, e.g., used to track indexed  * items.  *  * Note, however, that you can also define item types where some of these  * conditions are not met, as long as you are aware that some functionality of  * the Search API and related modules might then not be available for that type.  *  * @return array  *   An associative array keyed by item type identifier, and containing type  *   information arrays with at least the following keys:  *   - name: A human-readable name for the type.  *   - datasource controller: A class implementing the  *     SearchApiDataSourceControllerInterface interface which will be used as  *     the data source controller for this type.  *   - entity_type: (optional) If the type represents entities, the entity type.  *     This is used by SearchApiAbstractDataSourceController for determining the  *     entity type of items. Other datasource controllers might ignore this.  *   Other, datasource-specific settings might also be placed here. These should  *   be specified with the data source controller in question.  *  * @see hook_search_api_item_type_info_alter()  */ function hook_search_api_item_type_info() { /* ... */ } 
 
 
     
     

相关问题

2  如何在背景中关闭叠加点击  ( How to close overlay on background click ) 
请帮我在背景中封装封闭。我尝试了以下代码,但它不起作用: jQuery('.overlay-modal-background').live('click', function(e) { Drupal.overlay.close(); }); ...

1  编辑“默认前页”基本URL  ( Editing the default front page base url ) 
我从另一台服务器的图像重建了新服务器。我想将它用于新域,但我发现新服务器继续重定向到原始服务器的域。 进入新服务器的Drupal管理控制台,我看到域(即, https://mysite.com/)在配置下是不可分辨诚的。系统&gt;网站信息&gt;首页&gt;默认前页。 我尝试在/etc/drupal/7/sites...

2  从模块传递数组以在模板中呈现  ( Pass array from module to render in template ) 
我在该模块中有一个模块名称mysite mysite。我的函数名为mysite_preprocess_panels_pane。具有阵列,我想呈现此阵列Inn panel.tpl.php。我的代码不起作用。请问,谢谢。 function mysite_preprocess_panels_pane(&$variabl...

0  图像样式规模和裁剪不格式化  ( Image style scale and crop not formatting right ) 
我有一个规模和裁剪图像样式,但我必须将它移动到代码。所以,重新创建它,我的代码是: function mymodule_image_default_styles() { $styles = array(); $styles['mymodule_thumb'] = array( '...

0  布局详细信息节点+ CKEDITOTER布局  ( Layout detail node ckeditor layout ) 
当我创建这样的内容类型的节点时: 我可以添加图像,段落,......。但它在节点的详细信息页面上看起来如此: 没有图像,没有段落,......这可能是这个问题? 我正在使用过滤的HTML文本格式。当我检查段落的HTML时,没有图像,没有。只是文字...... 这些是我的上下文过滤器的设置过滤了HTML:...

1  如何以编程方式添加类以查看块  ( How to add class to view block programmatically ) 
我需要添加类以编程方式查看块,但无法找到工作方式。我的视图格式是未格式化的列表。 我在我的template.php中有这个: function theme_preprocess_block(&$variables){ // Add arbitrary class to specific block ...

0  如何在我的模块中注册Image_style主题函数,该函数仅在我的主题模板中工作?  ( How can i register a image style theme function in my module which only works in ) 
有没有办法告诉Drupal我的模块具有一个主题功能,通常只在我的主题中工作? 如果我在我的主题的template.php中写入: function mytheme_image_style($variables) { // Determine the dimensions of the styled imag...

5  使用规则模块自动将内容发布到LinkedIn帐户  ( Using rules module to auto post the content to linkedin account ) 
我正在使用drupal 7.我使用了 feeds 模块从RSS内容。所以我可以从RSS源中获取内容。现在 feed 内容类型随着RSS提供内容自动保存。所以现在我想自动发布 feeds 内容到Twitter,linkedin和facebook.i使用 Twitter 模块。 所以我可以自动将内容用规则模块到Face...

0  开发期间共享数据库?  ( Shared database during development ) 
有时我需要与一个以上中心为中心的开发人员协作,以帮助实现一个站点。因此,它们只是改变CSS和次要模板的变化。 我们过去处理的方式是我在本地工作。当我处于良好状态时,我将我的环境克隆到登台服务器。前端DEV然后通过SFTP上传他的更改。 我们想迈向我们在本地工作的设置。当然的问题是保持配置更改所有同步。我一直在使用功能...

0  上传图像临时和表格提交使其成为永久性  ( Upload image temporary and on form submit make it permanent ) 
我已经做了一个自定义模块,其中我加载了"公告" 内容类型的创建节点表单。 我想要的 除了文本和选择字段之外,我需要一个支持多个映像上传的图像字段(最多4个)。图像应将上传到临时目录并在表单中加载缩略图进行预览,并且在表单上提交图像应永久保存图像。如果我刷新表单页面,如果我已经选择了它们仍然应该在表单上显示为缩略...

1  现场集合模块Ajax错误  ( Field collection module ajax error ) 
我正在利用现场集合模块允许我将一个内容类型(例如,作者)与另一种内容类型相关联(例如,书籍)。 当我尝试使用作者部分中的"添加其他项目" 或"删除" 按钮时查看编辑页面时 - 通过AJAX运行 - 我收到AJAX以下URL上的"403禁止" 错误: field_collection/ajax 一个关键信息是...

1  将表单值写入数据库  ( Write form value to database ) 
我需要将此保存到数据库,但无法找到方法来使其工作。 现在,此PayPal_email仅保存到当前用户。显然它以某种方式保存到用户表下的数据库,但无法在那里读取?或使用视图阅读它。 function commerce_funds_manage_withdrawal_method_paypal($form, &$...

0  幻灯片在Safari或Chrome中不起作用  ( Slideshow does not work in safari or chrome ) 
我的幻灯片块在Firefox中工作,但不是在Chrome,Opera或Safari中。在这些浏览器中,我只需使用没有图像的控件。请注意,View Page(附件)也没有显示在其他浏览器中的图像预览。 ...

0  豆束类型  ( Bean bundle type ) 
我想在启用bean时使用hook_field_enable()来启用必填字段。为此,我需要知道捆绑包才能创建实例 $instance = array( 'field_name' => 'name of my field', 'entity_type' => '?', 'labe...

0  创建模块级主菜单替换  ( Creating a module level main menu replacement ) 
我想创建一个模块(不是主题),它替换/增强了Drupal 7中的主菜单。 我有一个CSS驱动菜单(Megamenu风格)。它是通用的,我想在项目/主题中重复使用它...因此我对模块的渴望。 (注意:我还将将此取决于WordPress插件,因此维护可重用的核心代码是一个高优先级。Drupal或Wordpress主题,可...

0  创建具有百置验证并提交的表单  ( Creating a form with get bypases the validation and submit ) 
我正在创建一个简单的形式,当Sumits时,显示来自外部API的结果。 但URL保持不变,因此如果您的搜索结果,您无法获得URL并将其发送给某人。 但是当我使用get 时 $form['method'] = 'get'; 它显示了一个约束的URL .. mysite.com/search?cat=2$...

3  drupal_add_js正在删除jquery  ( Drupal add js is removing jquery ) 
我的模块中有以下内容。 drupal_add_js( drupal_get_path('module', 'responsive_videos') . '/js/fluidvids.js', array( 'type' => 'file', 'scope' => '...

0  将数据插入表后,更新主页Drupal7中的数据  ( After insert data to table updating data in home page drupal7 ) 
我有一个用于将数据插入类别表的插入_data模块,我还有一个名为mysite的模块,该模块具有名为"function mysite_preprocess_panels_pane(&amp; $变量)" 的函数用于将数据呈现为panel.tbl。 PHP。 我的问题是我如何从MySite模块调用函数"mysite_pr...

1  如何为Excel Parser Drupal 7设置限制  ( How to set limit for excel parser drupal 7 ) 
我正在使用Feed进口商从Excel表导入用户。在我当地的WAMP服务器中,我可以导入超过170个用户。但是当我尝试在我的服务器上时,它不起作用。它显示: 发生了一个ajax HTTP错误。 HTTP结果代码:500调试 信息如下。路径:/批处理?ID = 2906&amp; op = do Statustex...

1  使用页面处理程序时包含字符编码(丹麦语æØÅ)的问题包括hook_menu()中的文件。  ( Problem with character encoding danish %c3%a6 %c3%b8 %c3%a5 when using page handler include ) 
当我使用.inc文件来处理我的页面输出时,所有丹麦特殊字符(æ,Ø和Å)显示为问号,即它们是用错误的字符编码呈现。 以下模块按预期工作。 stack_exchange_minimal.module <?php /** * Implements hook_menu(). */ function stack_ex...




© 2021 it.wenda123.org All Rights Reserved. 问答之家 版权所有


Licensed under cc by-sa 3.0 with attribution required.