duangou2028 2010-08-05 08:03
浏览 40
已采纳

找到未使用的PHP文件的技巧(Drupal模板文件)

I am looking for a trick to find included files that are not in use. Preferrably not by going trough them by hand. This project has over 400 of such files, 100 are probably unused by now.

They are Drupal template files (tpl.php) and were placed in the theme/template during development and -as always- were never removed when obsoleted.

Things I have thought of: * maintain a register in the database or a log, and spider the site. All files that don't appear in the log are candidates for removal, and need manual checking. * use a file-profiling tool such as cachegrind to render call-stacks: the files should appear in there somehow. I have no idea, however, how to get this done.

Problem in Drupal templates, is that they are very dynamic, so simply grepping for include_once() and the likes does not work.

How do you avoid template-lint in Drupal?

  • 写回答

1条回答 默认 最新

  • douba6361 2010-08-05 08:50
    关注

    Drupal registers every single theme implementation, including template files, in the theme registry. You could create a custom module and implement hook_theme_registry_alter() to inspect the theme registry to find what templates are being used by your theme. From there, you could compare your theme folder with the list you generated.

    Example implementation:

    function mymodule_theme_registry_alter(&$theme_registry) {
      global $theme_path;
    
      $templates_used = array();
    
      foreach ($theme_registry as $theme) {
        if (!empty($theme['template']) && $theme['path'] === $theme_path) {
          $templates_used[] = $theme['template'] . '.tpl.php';
        }
      }
    
      // Display the list (requires Devel module)
      dsm($templates_used);
    }
    

    Edit

    If you don't want to implement hook_theme_registry_alter(), you could use theme_get_registry() to get the theme registry array and use the above technique to check for template files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计