C_Base_Module

A Module will register utilities and adapters to provide it's functionality, and usually provide some classes for business logic.

Defined (1)

The class is defined in the following location(s).

/pope/lib/class.base_module.php  
  1. abstract class C_Base_Module 
  2. var $module_id; 
  3. var $module_name; 
  4. var $module_description; 
  5. var $module_version; 
  6. var $module_uri; 
  7. var $module_author; 
  8. var $module_author_uri; 
  9. var $module_type_list = null; 
  10. var $initialized = FALSE; 
  11.  
  12. function __construct() 
  13. // TODO: This is here to be compatible with the theme. Once the theme doesn't make use of $this->object 
  14. // when it doesn't have to, we can remove this circular reference 
  15. $this->object = $this; 
  16.  
  17. @$this->define(); 
  18.  
  19. function initialize() 
  20.  
  21.  
  22. function get_registry() 
  23. return C_Component_Registry::get_instance(); 
  24.  
  25. function _get_registry() 
  26. return C_Component_Registry::get_instance(); 
  27.  
  28. /** 
  29. * Defines the module 
  30. */ 
  31. function define($id='pope-module', $name='Pope Module', $description='', $version='', $uri='', $author='', $author_uri='', $context=FALSE) 
  32. $this->module_id = $id; 
  33. $this->module_name = $name; 
  34. $this->module_description = $description; 
  35. $this->module_version = $version; 
  36. $this->module_uri = $uri; 
  37. $this->module_author = $author; 
  38. $this->module_author_uri = $author_uri; 
  39.  
  40. $this->get_registry()->add_module($this->module_id, $this); 
  41.  
  42. function load() 
  43. // Package files may not exist until releases are built 
  44. $path = $this->get_package_abspath(); 
  45. if (@file_exists($path)) 
  46. @include_once($path); 
  47.  
  48. $this->_register_utilities(); 
  49. $this->_register_adapters(); 
  50. $this->_register_hooks(); 
  51.  
  52. function get_package_abspath() 
  53. $module_abspath = $this->get_registry()->get_module_path($this->module_id); 
  54. return str_replace('module.', 'package.module.', $module_abspath); 
  55.  
  56. /** 
  57. * I/O can be expensive to run repeatedly, so when a module is created we cache a listing of every file provided 
  58. * @return array List of types => files belonging to this module 
  59. */ 
  60. function get_type_list() 
  61. // XXX small hack to skip photocrati theme modules scans 
  62. $except_modules = array( 
  63. 'photocrati-gallery_legacy' => array(),  
  64. 'photocrati-theme_bulk' => array(),  
  65. 'photocrati-theme_admin' => array(),  
  66. 'photocrati-auto_update' => array( 
  67. 'A_Autoupdate_Settings' => 'adapter.autoupdate_settings.php' 
  68. ),  
  69. 'photocrati-auto_update-admin' => array( 
  70. 'A_Autoupdate_Admin_Ajax' => 'adapter.autoupdate_admin_ajax.php',  
  71. 'A_Autoupdate_Admin_Factory' => 'adapter.autoupdate_admin_factory.php',  
  72. 'C_Autoupdate_Admin_Ajax' => 'class.autoupdate_admin_ajax.php',  
  73. 'C_Autoupdate_Admin_Controller' => 'class.autoupdate_admin_controller.php' 
  74. )); 
  75.  
  76. if (isset($except_modules[$this->module_id])) 
  77. return $except_modules[$this->module_id]; 
  78.  
  79. if ($this->module_type_list === null) 
  80. {  
  81. $map = array( 
  82. 'C_' => 'class',  
  83. 'A_' => 'adapter',  
  84. 'I_' => 'interface',  
  85. 'Mixin_' => 'mixin',  
  86. 'M_' => 'module',  
  87. 'Hook_' => 'hook',  
  88. ); 
  89.  
  90. $type_list = array(); 
  91. $dir = $this->get_registry()->get_module_dir($this->module_id) . DIRECTORY_SEPARATOR; 
  92. $iterator = new RecursiveIteratorIterator( 
  93. new RecursiveDirectoryIterator($dir) 
  94. ); 
  95. foreach ($iterator as $filename) { 
  96. if (in_array(basename($filename->getPathname()), array('.', '..'))) 
  97. continue; 
  98.  
  99. $filename = str_replace($dir, '', $filename->getPathname()); 
  100. $file_parts = explode('.', $filename); 
  101. $prefix = $file_parts[0]; 
  102. $name = (!empty($file_parts[1]) ? $file_parts[1] : ''); 
  103. $name_prefix = array_search($prefix, $map); 
  104.  
  105. if ($name_prefix) 
  106. $type_name = $name_prefix . $name; 
  107.  
  108. $type_list[$type_name] = $filename; 
  109.  
  110. $this->module_type_list = $type_list; 
  111.  
  112. return $this->module_type_list; 
  113.  
  114. /** 
  115. * Provides a reliable means of determining if the current request is in the 
  116. * wp-admin panel 
  117. * @return boolean 
  118. */ 
  119. function is_admin() 
  120. return (is_admin() OR preg_match('/wp-admin/', $_SERVER['REQUEST_URI'])); 
  121.  
  122. /** 
  123. * Join two filesystem paths together (e.g. 'give me $path relative to $base'). 
  124. * If the $path is absolute, then the full path is returned. 
  125. * Taken from wordpress 3.4.1 
  126. * @param string $base 
  127. * @param string $path 
  128. * @return string The path with the base or absolute path 
  129. */ 
  130. function _path_join($base, $path) 
  131. if ($this->_path_is_absolute($path)) 
  132. return $path; 
  133. return trim($base, "/\\") . DIRECTORY_SEPARATOR . ltrim($path, "/\\"); 
  134.  
  135. /** 
  136. * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows'). 
  137. * Taken from wordpress 3.4.1 
  138. * @param string $path File path 
  139. * @return bool True if path is absolute, false is not absolute. 
  140. */ 
  141. function _path_is_absolute($path) 
  142. // this is definitive if true but fails if $path does not exist or contains a symbolic link 
  143. if (realpath($path) == $path) 
  144. return true; 
  145.  
  146. if (strlen($path) == 0 || $path[0] == '.') 
  147. return false; 
  148.  
  149. // windows allows absolute paths like this 
  150. if (preg_match('#^[a-zA-Z]:\\\\#', $path)) 
  151. return true; 
  152.  
  153. // a path starting with / or \ is absolute; anything else is relative 
  154. return ($path[0] == '/' || $path[0] == '\\'); 
  155.  
  156. function _register_hooks() {} 
  157. function _register_adapters() {} 
  158. function _register_utilities() {}