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. @include_once($this->get_package_abspath()); 
  44.  
  45. $this->_register_utilities(); 
  46. $this->_register_adapters(); 
  47. $this->_register_hooks(); 
  48.  
  49. function get_package_abspath() 
  50. $module_abspath = $this->get_registry()->get_module_path($this->module_id); 
  51. return str_replace('module.', 'package.module.', $module_abspath); 
  52.  
  53. /** 
  54. * I/O can be expensive to run repeatedly, so when a module is created we cache a listing of every file provided 
  55. * @return array List of types => files belonging to this module 
  56. */ 
  57. function get_type_list() 
  58. // XXX small hack to skip photocrati theme modules scans 
  59. $except_modules = array( 
  60. 'photocrati-gallery_legacy' => array(),  
  61. 'photocrati-theme_bulk' => array(),  
  62. 'photocrati-theme_admin' => array(),  
  63. 'photocrati-auto_update' => array( 
  64. 'A_Autoupdate_Settings' => 'adapter.autoupdate_settings.php' 
  65. ),  
  66. 'photocrati-auto_update-admin' => array( 
  67. 'A_Autoupdate_Admin_Ajax' => 'adapter.autoupdate_admin_ajax.php',  
  68. 'A_Autoupdate_Admin_Factory' => 'adapter.autoupdate_admin_factory.php',  
  69. 'C_Autoupdate_Admin_Ajax' => 'class.autoupdate_admin_ajax.php',  
  70. 'C_Autoupdate_Admin_Controller' => 'class.autoupdate_admin_controller.php' 
  71. )); 
  72.  
  73. if (isset($except_modules[$this->module_id])) 
  74. return $except_modules[$this->module_id]; 
  75.  
  76. if ($this->module_type_list === null) 
  77. {  
  78. $map = array( 
  79. 'C_' => 'class',  
  80. 'A_' => 'adapter',  
  81. 'I_' => 'interface',  
  82. 'Mixin_' => 'mixin',  
  83. 'M_' => 'module',  
  84. 'Hook_' => 'hook',  
  85. ); 
  86.  
  87. $type_list = array(); 
  88. $dir = $this->get_registry()->get_module_dir($this->module_id) . DIRECTORY_SEPARATOR; 
  89. $iterator = new RecursiveIteratorIterator( 
  90. new RecursiveDirectoryIterator($dir) 
  91. ); 
  92. foreach ($iterator as $filename) { 
  93. if (in_array(basename($filename->getPathname()), array('.', '..'))) 
  94. continue; 
  95.  
  96. $filename = str_replace($dir, '', $filename->getPathname()); 
  97. $file_parts = explode('.', $filename); 
  98. $prefix = $file_parts[0]; 
  99. $name = (!empty($file_parts[1]) ? $file_parts[1] : ''); 
  100. $name_prefix = array_search($prefix, $map); 
  101.  
  102. if ($name_prefix) 
  103. $type_name = $name_prefix . $name; 
  104.  
  105. $type_list[$type_name] = $filename; 
  106.  
  107. $this->module_type_list = $type_list; 
  108.  
  109. return $this->module_type_list; 
  110.  
  111. /** 
  112. * Provides a reliable means of determining if the current request is in the 
  113. * wp-admin panel 
  114. * @return boolean 
  115. */ 
  116. function is_admin() 
  117. return (is_admin() OR preg_match('/wp-admin/', $_SERVER['REQUEST_URI'])); 
  118.  
  119. /** 
  120. * Join two filesystem paths together (e.g. 'give me $path relative to $base'). 
  121. * If the $path is absolute, then the full path is returned. 
  122. * Taken from wordpress 3.4.1 
  123. * @param string $base 
  124. * @param string $path 
  125. * @return string The path with the base or absolute path 
  126. */ 
  127. function _path_join($base, $path) 
  128. if ($this->_path_is_absolute($path)) 
  129. return $path; 
  130. return trim($base, "/\\") . DIRECTORY_SEPARATOR . ltrim($path, "/\\"); 
  131.  
  132. /** 
  133. * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows'). 
  134. * Taken from wordpress 3.4.1 
  135. * @param string $path File path 
  136. * @return bool True if path is absolute, false is not absolute. 
  137. */ 
  138. function _path_is_absolute($path) 
  139. // this is definitive if true but fails if $path does not exist or contains a symbolic link 
  140. if (realpath($path) == $path) 
  141. return true; 
  142.  
  143. if (strlen($path) == 0 || $path[0] == '.') 
  144. return false; 
  145.  
  146. // windows allows absolute paths like this 
  147. if (preg_match('#^[a-zA-Z]:\\\\#', $path)) 
  148. return true; 
  149.  
  150. // a path starting with / or \ is absolute; anything else is relative 
  151. return ($path[0] == '/' || $path[0] == '\\'); 
  152.  
  153. function _register_hooks() {} 
  154. function _register_adapters() {} 
  155. function _register_utilities() {}