Member Login

Username:
Password:
Remember:

File Information

File Name: core.plugins.class.php
File Size: 9.92 KB
Uploaded By:  alec
MD5 Hash:
SHA1 Hash:
Downloads: 0
Page Views: 109
Date Uploaded: Jun 30th, 2009 at 6:26:03 pm
Last Downloaded:  File has not been downloaded
File Status:  Public File

Share File

core.plugins.class.php

Share This File

Unformatted Download URL:
HTML Download URL:
BBC Download URL:

File Contents

  1. <?php
  2. #
  3. # plugin class for LemurCMS
  4. #
  5. #
  6. if(class_exists('init')) {
  7. $initClass = new init(false);
  8. $initClass->getPluginList();
  9. }
  10. $pluginList = array(
  11. 'scripts' => array(),
  12. 'styles' => array('attachMessageCSS'),
  13. 'beforeBodyEnd' => array(),
  14. 'search' => array(),
  15. 'search-box' => array()
  16. );
  17. $pluginInterfaceList = array();
  18. function plugin ($location, $data = array()) {
  19. global $pluginList;
  20.  
  21. if( empty($pluginList[ $location ]) ) return;
  22. $plugins = $pluginList[ $location ];
  23. if( empty($plugins) ) return;
  24.  
  25. foreach( $plugins as $pFunc ) {
  26. if( is_callable( $pFunc ) )
  27. call_user_func_array( $pFunc, (array)$data );
  28. }
  29. }
  30. function registerPlugin( $pLocation, $pName ) {
  31. global $pluginList;
  32. if( !isset($pluginList[ $pLocation ]) ) {
  33. $pluginList[ $pLocation ] = array();
  34. }
  35. $pluginList[ $pLocation ] = array_merge( (array)$pluginList[ $pLocation ], (array)$pName );
  36. }
  37. function runInterface( $title) {
  38. global $pluginInterfaceList;
  39. if(array_key_exists( $title, (array) $pluginInterfaceList) && is_callable( $pluginInterfaceList[$title] ))
  40. call_user_func( $pluginInterfaceList[$title]);
  41. }
  42. function runInstall ( $plugin ) {
  43. global $pluginInstall;
  44. if( is_callable( $pluginInstall[$plugin] ) )
  45. call_user_func( $pluginInstall[$plugin] );
  46. }
  47. function runUninstall ( $plugin ) {
  48. global $pluginUninstall;
  49. if( is_callable( $pluginUninstall[$plugin] ) )
  50. call_user_func( $pluginUninstall[$plugin] );
  51. }
  52. $optionsRun = false;
  53. class Plugin extends functions {
  54. public $pluginName;
  55. public $visName;
  56. public $Interface;
  57. public $isActive = false;
  58. public $options = false;
  59. public $SERVER_ROOT = BASE_URL, $VISUAL_ROOT = THEME_URL;
  60.  
  61. public function Plugin( $pN ) {
  62. if($pN !== false) {
  63. global $initClass;
  64. global $pluginData;
  65. $activePlugins = $initClass->activePlugins;
  66. $this->pluginName = $this->make_clean_url($pN);
  67. $pluginData[ $this->pluginName ][ 'name' ] = $pN;
  68. $this->visName = $pN;
  69. if( in_array($this->visName, (array)$activePlugins ) ) {
  70. $this->isActive = true;
  71. }
  72. else {
  73. $this->isActive = false;
  74. }
  75. }
  76. }
  77. public function addPlugin( $location, $callFunction ) {
  78. global $initClass;
  79. global $pluginList;
  80. if( !isset($pluginList[ $pLocation ]) ) {
  81. $pluginList[ $pLocation ] = array();
  82. }
  83. if( !$this->isActive ) return;
  84. if( empty($this->pluginName) )
  85. $page->message('Error', 'Plugin Error', 'Plugin Name not specified');
  86.  
  87. global $pluginData;
  88. $pluginData[ $this->visName ][ 'plugins' ][] = array( 'location'=>$location , 'callFunction'=>$callFunction );
  89. if(array_key_exists($this->visName , $initClass->dbPluginList)) {
  90.  
  91. }
  92. else {
  93. $options = serialize(array('active'=>'no'));
  94. $sql = "INSERT INTO ".DBTABLEPREFIX."plugins (name, options) VALUES ('{$pluginData[ $this->visName ][ 'name' ]}', '{$options}')";
  95. $query = $this->db_query($sql) or die($this->message('error', 'MySQL Error', $this->db->error()));
  96. }
  97. registerPlugin( $location, $callFunction );
  98. }
  99. public function description( $desc ) {
  100. global $pluginData;
  101. $pluginData[ $this->pluginName ][ 'desc' ] = $desc;
  102. }
  103. public function version( $desc ) {
  104. global $pluginData;
  105. $pluginData[ $this->pluginName ][ 'version' ] = $desc;
  106. }
  107. public function author( $auth ) {
  108. global $pluginData;
  109. $pluginData[ $this->pluginName ][ 'author' ] = $auth;
  110. }
  111. public function addUninstall ( $func ) {
  112. global $pluginUninstall;
  113. $pluginUninstall [ $this->visName ] = $func;
  114. }
  115. public function addInstall ( $func ) {
  116. global $pluginInstall;
  117. $pluginInstall [ $this->visName ] = $func;
  118. }
  119. public function addInterface( $interfaceFunc ) {
  120. global $pluginData;
  121. global $pluginInterfaceList;
  122. $pluginInterfaceList[$this->pluginName] = $interfaceFunc;
  123. $pluginData[ $this->pluginName ][ 'interface' ] = $interfaceFunc;
  124. }
  125. // Format for adding page
  126. // @param str: page title
  127. // @param str: menu title
  128. // @param str: content
  129. // @param str: weight
  130. // @param str: parent_id
  131. // @param str: secondary
  132. // @param str: options
  133. //
  134. public function addPage ($pageTitle, $menuTitle, $content, $weight = '0', $parentId = '0', $secondary = '', $options = 'a:0:{}') {
  135. if(is_array($options))
  136. $options = serialize($options);
  137. $pageTitle = addslashes($pageTitle);
  138. $menuTitle = addslashes($menuTitle);
  139. $content = addslashes($content);
  140. $options = addslashes($options);
  141. $sql = "INSERT INTO ".DBTABLEPREFIX."content_pages (title, content, orderingid, menutitle, parent_id, time, secondary, options)
  142. VALUES ('$pageTitle', '$content', '$weight', '$menuTitle', '$weight', '$parentId', '$secondary', '$options')";
  143. $query = $this->db->query($sql) or die($this->db->error());
  144. }
  145. public function addOption ($name, $value) {
  146. $plugin = $this->visName;
  147. if(!$this->getOption($plugin, $name)) {
  148. $name = addSlashes($name);
  149. $plugin = addSlashes($plugin);
  150. if(is_array($value))
  151. $value = serialize($value);
  152. $value = addSlashes($value);
  153. $sql = "INSERT INTO ".DBTABLEPREFIX."plugins_settings (plugin, field_name, data)
  154. VALUES ('$plugin', '$name', '$value')";
  155. $query = $this->db_query($sql);
  156. return $query;
  157. }
  158. else {
  159. return true;
  160. }
  161. }
  162. public function updateOption ($name, $value) {
  163. global $allOptions;
  164. $plugin = $this->visName;
  165. $this->getAllOptions();
  166. $name = addSlashes($name);
  167. $plugin = addSlashes($plugin);
  168. if(is_array($value))
  169. $value = serialize($value);
  170. $value = addSlashes($value);
  171. if(array_key_exists($name, (array) $allOptions[$plugin]))
  172. $sql = "UPDATE ".DBTABLEPREFIX."plugins_settings SET data = '{$value}' WHERE plugin = '{$plugin}' AND field_name = '{$name}'";
  173. else
  174. $sql = "INSERT INTO ".DBTABLEPREFIX."plugins_settings (plugin, field_name, data) VALUES ('{$plugin}', '{$name}', '{$value}')";
  175. $query = $this->db_query($sql) or die($this->db->error());
  176. $this->getAllOptions(true);
  177. return $query;
  178. }
  179. public function deleteOption ($name) {
  180. $plugin = $this->visName;
  181. $sql = "DELETE FROM ".DBTABLEPREFIX."plugins_settings WHERE plugin = '{$plugin}' AND field_name = '{$name}'";
  182. $query = $this->db_query($sql);
  183. return $query;
  184. }
  185. public function getOption ($name) {
  186. global $optionsRun, $allOptions;
  187. $plugin = $this->visName;
  188. if(empty($allOptions)) {
  189. $this->getAllOptions();
  190. }
  191. if(array_key_exists($name, (array) $allOptions[$plugin]))
  192. return $allOptions[$plugin][$name];
  193. else
  194. return false;
  195. }
  196. public function getAllOptions ($reset = false) {
  197. global $optionsRun, $allOptions;
  198. $plugin = $this->visName;
  199. if($optionsRun == false || $reset == true) {
  200. $sql = "SELECT * FROM ".DBTABLEPREFIX."plugins_settings";
  201. $query = $this->db_query($sql) or die($this->db->error());
  202. while($row = $this->db->fetchAssoc($query)) {
  203. foreach($row as $key => $value) {
  204. $row[$key] = stripcslashes(stripcslashes($value));
  205. }
  206. // var_dump($row);
  207. if(unserialize($row['data']))
  208. $allOptions[$row['plugin']][$row['field_name']] = unserialize($row['data']);
  209. else
  210. $allOptions[$row['plugin']][$row['field_name']] = stripcslashes(stripcslashes($row['data']));
  211. }
  212. $optionsRun = true;
  213. }
  214. if($allOptions !== false)
  215. return $allOptions[$plugin];
  216. else
  217. return false;
  218. }
  219. public function addSidebarBlock ($title, $func) {
  220. global $pluginData;
  221. $pluginData[$this->pluginName][ 'sidebar' ][] = array( 'title'=>$title, 'callFunction'=>$func );
  222. }
  223. public function addDashboardBlock ($title, $func, $column = '1') {
  224. global $pluginData;
  225. $pluginData[ 'dashboard' ][] = array( 'title'=>$title, 'callFunction'=>$func , 'column' =>$column);
  226. }
  227. public function addPermission ($name, $value) {
  228. $perUrl = BASE_URL.'includes/admin/permissions.php';
  229. $per = unserialize(file_get_contents($perUrl));
  230. foreach($per as $level => $arrtrue) {
  231. foreach($arrtrue as $cat => $arr2) {
  232. if($cat == 'Individual Actions') {
  233. //var_dump($newPer[$level][$cat]);
  234. $per[$level][$cat][$name] = (bool) $value;
  235. }
  236. }
  237. }
  238. file_put_contents($perUrl, serialize($per));
  239. }
  240. public function updatePermission ($name, $value) {
  241. $this->addPermission($name, $value);
  242. }
  243. public function removePermission ($name) {
  244. $perUrl = BASE_URL.'includes/admin/permissions.php';
  245. $per = unserialize(file_get_contents($perUrl));
  246. foreach($per as $level => $arrtrue) {
  247. foreach($arrtrue as $cat => $arr2) {
  248. if($cat == 'Individual Actions') {
  249. unset($per[$level][$cat][$name]);
  250. }
  251. }
  252. }
  253. file_put_contents($perUrl, serialize($per));
  254. }
  255. /*
  256. Message Functions
  257. */
  258. public function message($type = 'message', $header = "", $content = "", $small = false) {
  259. $r .= "<div class='message-wrapper";
  260. if($small == true) {
  261. $r .= ' message-small';
  262. }
  263. else {
  264. $r .= ' message-large';
  265. }
  266. $r .= "'>";
  267. switch ($type) {
  268. case 'message':
  269. $r .= "<div class='message-message message'>nt<div class='message-message-header message-header'>".$header."</div>nt<div class='message-message-content message-content'>ntt<p>".$content."</p>nt</div>n</div>";
  270. break;
  271. case 'success':
  272. $r .= "<div class='message-ok message'>nt<div class='message-ok-header message-header'>".$header."</div>nt<div class='message-ok-content message-content'>ntt<p>".$content."</p>nt</div>n</div>";
  273. break;
  274. case 'error':
  275. $r .= "<div class='message-error message'>nt<div class='message-error-header message-header'>".$header."</div>nt<div class='message-error-content message-content'>ntt<p>".$content."</p>nt</div>n</div>";
  276. break;
  277. case 'warning':
  278. $r .= "<div class='message-warning message'>nt<div class='message-warning-header message-header'>".$header."</div>nt<div class='message-warning-content message-content'>ntt<p>".$content."</p>nt</div>n</div>";
  279. break;
  280. }
  281. $r .= "</div>";
  282. return $r;
  283. }
  284. }
  285. function attachMessageCSS () {
  286. echo '<style type="text/css">@import "'.THEME_URL.'includes/admin/css/messages.css";</style>
  287. ';
  288. }
  289. ?>

By downloading this file, you agree to our Terms of Service and Privacy Policy. If this file violates our terms of service, please report it. Report file