plugin.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Plugin
  5. * Base class for plugins
  6. *
  7. * This class has to be extended by every plugin. It defines basic methods
  8. * to install/uninstall and get information about a plugin
  9. *
  10. * @author Julio Montoya <gugli100@gmail.com>
  11. * @author Yannick Warnier <ywarnier@beeznest.org>
  12. * @author Laurent Opprecht <laurent@opprecht.info>
  13. * @copyright 2012 University of Geneva
  14. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  15. *
  16. */
  17. class Plugin
  18. {
  19. protected $version = '';
  20. protected $author = '';
  21. protected $fields = [];
  22. private $settings = [];
  23. // Translation strings.
  24. private $strings = null;
  25. public $isCoursePlugin = false;
  26. public $isAdminPlugin = false;
  27. public $isMailPlugin = false;
  28. // Adds icon in the course home
  29. public $addCourseTool = true;
  30. /**
  31. * When creating a new course, these settings are added to the course, in
  32. * the course_info/infocours.php
  33. * To show the plugin course icons you need to add these icons:
  34. * main/img/icons/22/plugin_name.png
  35. * main/img/icons/64/plugin_name.png
  36. * main/img/icons/64/plugin_name_na.png
  37. * @example
  38. * $course_settings = array(
  39. array('name' => 'big_blue_button_welcome_message', 'type' => 'text'),
  40. array('name' => 'big_blue_button_record_and_store', 'type' => 'checkbox')
  41. );
  42. */
  43. public $course_settings = array();
  44. /**
  45. * This indicates whether changing the setting should execute the callback
  46. * function.
  47. */
  48. public $course_settings_callback = false;
  49. /**
  50. * Default constructor for the plugin class. By default, it only sets
  51. * a few attributes of the object
  52. * @param string $version of this plugin
  53. * @param string $author of this plugin
  54. * @param array $settings settings to be proposed to configure the plugin
  55. */
  56. protected function __construct($version, $author, $settings = array())
  57. {
  58. $this->version = $version;
  59. $this->author = $author;
  60. $this->fields = $settings;
  61. global $language_files;
  62. $language_files[] = 'plugin_'.$this->get_name();
  63. }
  64. /**
  65. * Gets an array of information about this plugin (name, version, ...)
  66. * @return array Array of information elements about this plugin
  67. */
  68. public function get_info()
  69. {
  70. $result = array();
  71. $result['obj'] = $this;
  72. $result['title'] = $this->get_title();
  73. $result['comment'] = $this->get_comment();
  74. $result['version'] = $this->get_version();
  75. $result['author'] = $this->get_author();
  76. $result['plugin_class'] = get_class($this);
  77. $result['is_course_plugin'] = $this->isCoursePlugin;
  78. $result['is_admin_plugin'] = $this->isAdminPlugin;
  79. $result['is_mail_plugin'] = $this->isMailPlugin;
  80. if ($form = $this->get_settings_form()) {
  81. $result['settings_form'] = $form;
  82. foreach ($this->fields as $name => $type) {
  83. $value = $this->get($name);
  84. if (is_array($type)) {
  85. $value = $type['options'];
  86. }
  87. $result[$name] = $value;
  88. }
  89. }
  90. return $result;
  91. }
  92. /**
  93. * Returns the "system" name of the plugin in lowercase letters
  94. * @return string
  95. */
  96. public function get_name()
  97. {
  98. $result = get_class($this);
  99. $result = str_replace('Plugin', '', $result);
  100. $result = strtolower($result);
  101. return $result;
  102. }
  103. /**
  104. * Returns the title of the plugin
  105. * @return string
  106. */
  107. public function get_title()
  108. {
  109. return $this->get_lang('plugin_title');
  110. }
  111. /**
  112. * Returns the description of the plugin
  113. * @return string
  114. */
  115. public function get_comment()
  116. {
  117. return $this->get_lang('plugin_comment');
  118. }
  119. /**
  120. * Returns the version of the plugin
  121. * @return string
  122. */
  123. public function get_version()
  124. {
  125. return $this->version;
  126. }
  127. /**
  128. * Returns the author of the plugin
  129. * @return string
  130. */
  131. public function get_author()
  132. {
  133. return $this->author;
  134. }
  135. /**
  136. * Returns the contents of the CSS defined by the plugin
  137. * @return string
  138. */
  139. public function get_css()
  140. {
  141. $name = $this->get_name();
  142. $path = api_get_path(SYS_PLUGIN_PATH)."$name/resources/$name.css";
  143. if (!is_readable($path)) {
  144. return '';
  145. }
  146. $css = array();
  147. $css[] = file_get_contents($path);
  148. $result = implode($css);
  149. return $result;
  150. }
  151. /**
  152. * Returns an HTML form (generated by FormValidator) of the plugin settings
  153. * @return FormValidator FormValidator-generated form
  154. */
  155. public function get_settings_form()
  156. {
  157. $result = new FormValidator($this->get_name());
  158. $defaults = array();
  159. $checkboxGroup = array();
  160. $checkboxCollection = array();
  161. if ($checkboxNames = array_keys($this->fields, 'checkbox')) {
  162. $pluginInfoCollection = api_get_settings('Plugins');
  163. foreach ($pluginInfoCollection as $pluginInfo) {
  164. if (array_search($pluginInfo['title'], $checkboxNames) !== false) {
  165. $checkboxCollection[$pluginInfo['title']] = $pluginInfo;
  166. }
  167. }
  168. }
  169. foreach ($this->fields as $name => $type) {
  170. $options = null;
  171. if (is_array($type) && isset($type['type']) && $type['type'] === 'select') {
  172. $options = $type['options'];
  173. $type = $type['type'];
  174. }
  175. $value = $this->get($name);
  176. $defaults[$name] = $value;
  177. $type = isset($type) ? $type : 'text';
  178. $help = null;
  179. if ($this->get_lang_plugin_exists($name.'_help')) {
  180. $help = $this->get_lang($name.'_help');
  181. if ($name === "show_main_menu_tab") {
  182. $pluginName = strtolower(str_replace('Plugin', '', get_class($this)));
  183. $pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php";
  184. $pluginUrl = "<a href=$pluginUrl>$pluginUrl</a>";
  185. $help = sprintf($help, $pluginUrl);
  186. }
  187. }
  188. switch ($type) {
  189. case 'html':
  190. $result->addElement('html', $this->get_lang($name));
  191. break;
  192. case 'wysiwyg':
  193. $result->addHtmlEditor($name, $this->get_lang($name), false);
  194. break;
  195. case 'text':
  196. $result->addElement($type, $name, array($this->get_lang($name), $help));
  197. break;
  198. case 'boolean':
  199. $group = array();
  200. $group[] = $result->createElement('radio', $name, '', get_lang('Yes'), 'true');
  201. $group[] = $result->createElement('radio', $name, '', get_lang('No'), 'false');
  202. $result->addGroup($group, null, array($this->get_lang($name), $help));
  203. break;
  204. case 'checkbox':
  205. $selectedValue = null;
  206. if (isset($checkboxCollection[$name])) {
  207. if ($checkboxCollection[$name]['selected_value'] === 'true') {
  208. $selectedValue = 'checked';
  209. }
  210. }
  211. $element = $result->createElement(
  212. $type,
  213. $name,
  214. '',
  215. $this->get_lang($name),
  216. $selectedValue
  217. );
  218. $element->_attributes['value'] = 'true';
  219. $checkboxGroup[] = $element;
  220. break;
  221. case 'select':
  222. $result->addElement(
  223. $type,
  224. $name,
  225. array($this->get_lang($name), $help),
  226. $options
  227. );
  228. break;
  229. }
  230. }
  231. if (!empty($checkboxGroup)) {
  232. $result->addGroup($checkboxGroup, null, array($this->get_lang('sms_types'), $help));
  233. }
  234. $result->setDefaults($defaults);
  235. $result->addButtonSave($this->get_lang('Save'), 'submit_button');
  236. return $result;
  237. }
  238. /**
  239. * Returns the value of a given plugin global setting
  240. * @param string $name of the plugin
  241. *
  242. * @return string Value of the plugin
  243. */
  244. public function get($name)
  245. {
  246. $settings = $this->get_settings();
  247. foreach ($settings as $setting) {
  248. if ($setting['variable'] == $this->get_name().'_'.$name) {
  249. return $setting['selected_value'];
  250. }
  251. }
  252. return false;
  253. }
  254. /**
  255. * Returns an array with the global settings for this plugin
  256. * @return array Plugin settings as an array
  257. */
  258. public function get_settings()
  259. {
  260. if (empty($this->settings)) {
  261. $settings = api_get_settings_params(
  262. array(
  263. "subkey = ? AND category = ? AND type = ? " => array($this->get_name(), 'Plugins', 'setting')
  264. )
  265. );
  266. $this->settings = $settings;
  267. }
  268. return $this->settings;
  269. }
  270. /**
  271. * Tells whether language variables are defined for this plugin or not
  272. * @param string $name System name of the plugin
  273. *
  274. * @return bool True if the plugin has language variables defined, false otherwise
  275. */
  276. public function get_lang_plugin_exists($name)
  277. {
  278. return isset($this->strings[$name]);
  279. }
  280. /**
  281. * Hook for the get_lang() function to check for plugin-defined language terms
  282. * @param string $name of the language variable we are looking for
  283. *
  284. * @return string The translated language term of the plugin
  285. */
  286. public function get_lang($name)
  287. {
  288. // Check whether the language strings for the plugin have already been
  289. // loaded. If so, no need to load them again.
  290. if (is_null($this->strings)) {
  291. global $language_interface;
  292. $root = api_get_path(SYS_PLUGIN_PATH);
  293. $plugin_name = $this->get_name();
  294. $interfaceLanguageId = api_get_language_id($language_interface);
  295. $interfaceLanguageInfo = api_get_language_info($interfaceLanguageId);
  296. $languageParentId = !empty($interfaceLanguageInfo['parent_id']) ? (int) $interfaceLanguageInfo['parent_id'] : 0;
  297. //1. Loading english if exists
  298. $english_path = $root.$plugin_name."/lang/english.php";
  299. if (is_readable($english_path)) {
  300. $strings = array();
  301. include $english_path;
  302. $this->strings = $strings;
  303. }
  304. $path = $root.$plugin_name."/lang/$language_interface.php";
  305. // 2. Loading the system language
  306. if (is_readable($path)) {
  307. include $path;
  308. if (!empty($strings)) {
  309. foreach ($strings as $key => $string) {
  310. $this->strings[$key] = $string;
  311. }
  312. }
  313. } elseif ($languageParentId > 0) {
  314. $languageParentInfo = api_get_language_info($languageParentId);
  315. $languageParentFolder = $languageParentInfo['dokeos_folder'];
  316. $parentPath = "{$root}{$plugin_name}/lang/{$languageParentFolder}.php";
  317. if (is_readable($parentPath)) {
  318. include $parentPath;
  319. if (!empty($strings)) {
  320. foreach ($strings as $key => $string) {
  321. $this->strings[$key] = $string;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. if (isset($this->strings[$name])) {
  328. return $this->strings[$name];
  329. }
  330. return get_lang($name);
  331. }
  332. /**
  333. * Caller for the install_course_fields() function
  334. * @param int $courseId
  335. *
  336. * @param boolean $addToolLink Whether to add a tool link on the course homepage
  337. *
  338. * @return void
  339. */
  340. public function course_install($courseId, $addToolLink = true)
  341. {
  342. $this->install_course_fields($courseId, $addToolLink);
  343. }
  344. /**
  345. * Add course settings and, if not asked otherwise, add a tool link on the course homepage
  346. * @param int $courseId Course integer ID
  347. * @param boolean $add_tool_link Whether to add a tool link or not
  348. * (some tools might just offer a configuration section and act on the backend)
  349. *
  350. * @return boolean|null False on error, null otherwise
  351. */
  352. public function install_course_fields($courseId, $add_tool_link = true)
  353. {
  354. $plugin_name = $this->get_name();
  355. $t_course = Database::get_course_table(TABLE_COURSE_SETTING);
  356. $courseId = (int) $courseId;
  357. if (empty($courseId)) {
  358. return false;
  359. }
  360. // Adding course settings.
  361. if (!empty($this->course_settings)) {
  362. foreach ($this->course_settings as $setting) {
  363. $variable = $setting['name'];
  364. $value = '';
  365. if (isset($setting['init_value'])) {
  366. $value = $setting['init_value'];
  367. }
  368. $type = 'textfield';
  369. if (isset($setting['type'])) {
  370. $type = $setting['type'];
  371. }
  372. if (isset($setting['group'])) {
  373. $group = $setting['group'];
  374. $sql = "SELECT value
  375. FROM $t_course
  376. WHERE
  377. c_id = $courseId AND
  378. variable = '".Database::escape_string($group)."' AND
  379. subkey = '".Database::escape_string($variable)."'
  380. ";
  381. $result = Database::query($sql);
  382. if (!Database::num_rows($result)) {
  383. $params = [
  384. 'c_id' => $courseId,
  385. 'variable' => $group,
  386. 'subkey' => $variable,
  387. 'value' => $value,
  388. 'category' => 'plugins',
  389. 'type' => $type,
  390. 'title' => ''
  391. ];
  392. Database::insert($t_course, $params);
  393. }
  394. } else {
  395. $sql = "SELECT value FROM $t_course
  396. WHERE c_id = $courseId AND variable = '$variable' ";
  397. $result = Database::query($sql);
  398. if (!Database::num_rows($result)) {
  399. $params = [
  400. 'c_id' => $courseId,
  401. 'variable' => $variable,
  402. 'subkey' => $plugin_name,
  403. 'value' => $value,
  404. 'category' => 'plugins',
  405. 'type' => $type,
  406. 'title' => ''
  407. ];
  408. Database::insert($t_course, $params);
  409. }
  410. }
  411. }
  412. }
  413. // Stop here if we don't want a tool link on the course homepage
  414. if (!$add_tool_link) {
  415. return true;
  416. }
  417. if ($this->addCourseTool == false) {
  418. return true;
  419. }
  420. //Add an icon in the table tool list
  421. $table = Database::get_course_table(TABLE_TOOL_LIST);
  422. $sql = "SELECT name FROM $table
  423. WHERE c_id = $courseId AND name = '$plugin_name' ";
  424. $result = Database::query($sql);
  425. if (!Database::num_rows($result)) {
  426. $tool_link = "$plugin_name/start.php";
  427. $cToolId = AddCourse::generateToolId($courseId);
  428. Database::insert(
  429. $table,
  430. [
  431. 'id' => $cToolId,
  432. 'c_id' => $courseId,
  433. 'name' => $plugin_name,
  434. 'link' => $tool_link,
  435. 'image' => "$plugin_name.png",
  436. 'visibility' => 1,
  437. 'admin' => 0,
  438. 'address' => 'squaregrey.gif',
  439. 'added_tool' => 0,
  440. 'target' => '_self',
  441. 'category' => 'plugin',
  442. 'session_id' => 0
  443. ]
  444. );
  445. }
  446. }
  447. /**
  448. * Delete the fields added to the course settings page and the link to the
  449. * tool on the course's homepage
  450. * @param int $courseId
  451. *
  452. * @return false|null
  453. */
  454. public function uninstall_course_fields($courseId)
  455. {
  456. $courseId = intval($courseId);
  457. if (empty($courseId)) {
  458. return false;
  459. }
  460. $plugin_name = $this->get_name();
  461. $t_course = Database::get_course_table(TABLE_COURSE_SETTING);
  462. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  463. if (!empty($this->course_settings)) {
  464. foreach ($this->course_settings as $setting) {
  465. $variable = Database::escape_string($setting['name']);
  466. if (!empty($setting['group'])) {
  467. $variable = Database::escape_string($setting['group']);
  468. }
  469. if (empty($variable)) {
  470. continue;
  471. }
  472. $sql = "DELETE FROM $t_course
  473. WHERE c_id = $courseId AND variable = '$variable'";
  474. Database::query($sql);
  475. }
  476. }
  477. $plugin_name = Database::escape_string($plugin_name);
  478. $sql = "DELETE FROM $t_tool
  479. WHERE c_id = $courseId AND name = '$plugin_name'";
  480. Database::query($sql);
  481. }
  482. /**
  483. * Install the course fields and tool link of this plugin in all courses
  484. * @param boolean $add_tool_link Whether we want to add a plugin link on the course homepage
  485. *
  486. * @return void
  487. */
  488. public function install_course_fields_in_all_courses($add_tool_link = true)
  489. {
  490. // Update existing courses to add plugin settings
  491. $t_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  492. $sql = "SELECT id FROM $t_courses ORDER BY id";
  493. $res = Database::query($sql);
  494. while ($row = Database::fetch_assoc($res)) {
  495. $this->install_course_fields($row['id'], $add_tool_link);
  496. }
  497. }
  498. /**
  499. * Uninstall the plugin settings fields from all courses
  500. * @return void
  501. */
  502. public function uninstall_course_fields_in_all_courses()
  503. {
  504. // Update existing courses to add conference settings
  505. $t_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  506. $sql = "SELECT id FROM $t_courses
  507. ORDER BY id";
  508. $res = Database::query($sql);
  509. while ($row = Database::fetch_assoc($res)) {
  510. $this->uninstall_course_fields($row['id']);
  511. }
  512. }
  513. /**
  514. * @return array
  515. */
  516. public function getCourseSettings()
  517. {
  518. $settings = array();
  519. if (is_array($this->course_settings)) {
  520. foreach ($this->course_settings as $item) {
  521. if (isset($item['group'])) {
  522. if (!in_array($item['group'], $settings)) {
  523. $settings[] = $item['group'];
  524. }
  525. } else {
  526. $settings[] = $item['name'];
  527. }
  528. }
  529. }
  530. return $settings;
  531. }
  532. /**
  533. * Method to be extended when changing the setting in the course
  534. * configuration should trigger the use of a callback method
  535. * @param array $values sent back from the course configuration script
  536. *
  537. * @return void
  538. */
  539. public function course_settings_updated($values = array())
  540. {
  541. }
  542. /**
  543. * Add a tab to platform
  544. * @param string $tabName
  545. * @param string $url
  546. *
  547. * @return false|string
  548. */
  549. public function addTab($tabName, $url)
  550. {
  551. $sql = "SELECT * FROM settings_current
  552. WHERE
  553. variable = 'show_tabs' AND
  554. subkey LIKE 'custom_tab_%'";
  555. $result = Database::query($sql);
  556. $customTabsNum = Database::num_rows($result);
  557. $tabNum = $customTabsNum + 1;
  558. // Avoid Tab Name Spaces
  559. $tabNameNoSpaces = preg_replace('/\s+/', '', $tabName);
  560. $subkeytext = "Tabs".$tabNameNoSpaces;
  561. // Check if it is already added
  562. $checkCondition = array(
  563. 'where' =>
  564. array(
  565. "variable = 'show_tabs' AND subkeytext = ?" => array(
  566. $subkeytext
  567. )
  568. )
  569. );
  570. $checkDuplicate = Database::select('*', 'settings_current', $checkCondition);
  571. if (!empty($checkDuplicate)) {
  572. return false;
  573. }
  574. // End Check
  575. $subkey = 'custom_tab_'.$tabNum;
  576. $attributes = array(
  577. 'variable' => 'show_tabs',
  578. 'subkey' => $subkey,
  579. 'type' => 'checkbox',
  580. 'category' => 'Platform',
  581. 'selected_value' => 'true',
  582. 'title' => $tabName,
  583. 'comment' => $url,
  584. 'subkeytext' => $subkeytext,
  585. 'access_url' => 1,
  586. 'access_url_changeable' => 0,
  587. 'access_url_locked' => 0
  588. );
  589. $resp = Database::insert('settings_current', $attributes);
  590. // Save the id
  591. $settings = $this->get_settings();
  592. $setData = array(
  593. 'comment' => $subkey
  594. );
  595. $whereCondition = array(
  596. 'id = ?' => key($settings)
  597. );
  598. Database::update('settings_current', $setData, $whereCondition);
  599. return $resp;
  600. }
  601. /**
  602. * Delete a tab to chamilo's platform
  603. * @param string $key
  604. * @return boolean $resp Transaction response
  605. */
  606. public function deleteTab($key)
  607. {
  608. $t = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  609. $sql = "SELECT *
  610. FROM $t
  611. WHERE variable = 'show_tabs'
  612. AND subkey <> '$key'
  613. AND subkey like 'custom_tab_%'
  614. ";
  615. $resp = $result = Database::query($sql);
  616. $customTabsNum = Database::num_rows($result);
  617. if (!empty($key)) {
  618. $whereCondition = array(
  619. 'variable = ? AND subkey = ?' => array('show_tabs', $key)
  620. );
  621. $resp = Database::delete('settings_current', $whereCondition);
  622. //if there is more than one tab
  623. //re enumerate them
  624. if (!empty($customTabsNum) && $customTabsNum > 0) {
  625. $tabs = Database::store_result($result, 'ASSOC');
  626. $i = 1;
  627. foreach ($tabs as $row) {
  628. $attributes = array(
  629. 'subkey' => 'custom_tab_'.$i
  630. );
  631. $this->updateTab($row['subkey'], $attributes);
  632. $i++;
  633. }
  634. }
  635. }
  636. return $resp;
  637. }
  638. /**
  639. * Update the tabs attributes
  640. * @param string $key
  641. * @param array $attributes
  642. *
  643. * @return boolean
  644. */
  645. public function updateTab($key, $attributes)
  646. {
  647. $whereCondition = array(
  648. 'variable = ? AND subkey = ?' => array('show_tabs', $key)
  649. );
  650. $resp = Database::update('settings_current', $attributes, $whereCondition);
  651. return $resp;
  652. }
  653. /**
  654. * This method shows or hides plugin's tab
  655. * @param boolean $showTab Shows or hides the main menu plugin tab
  656. * @param string $filePath Plugin starter file path
  657. */
  658. public function manageTab($showTab, $filePath = 'index.php')
  659. {
  660. $langString = str_replace('Plugin', '', get_class($this));
  661. $pluginName = strtolower($langString);
  662. $pluginUrl = 'plugin/'.$pluginName.'/'.$filePath;
  663. if ($showTab === 'true') {
  664. $tabAdded = $this->addTab($langString, $pluginUrl);
  665. if ($tabAdded) {
  666. // The page must be refreshed to show the recently created tab
  667. echo "<script>location.href = '".Security::remove_XSS($_SERVER['REQUEST_URI'])."';</script>";
  668. }
  669. } else {
  670. $settingsCurrentTable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  671. $conditions = array(
  672. 'where' => array(
  673. "variable = 'show_tabs' AND title = ? AND comment = ? " => array(
  674. $langString,
  675. $pluginUrl
  676. )
  677. )
  678. );
  679. $result = Database::select('subkey', $settingsCurrentTable, $conditions);
  680. if (!empty($result)) {
  681. $this->deleteTab($result[0]['subkey']);
  682. }
  683. }
  684. }
  685. /**
  686. * @param string $variable
  687. * @return bool
  688. */
  689. public function validateCourseSetting($variable)
  690. {
  691. return true;
  692. }
  693. /**
  694. * @param string $region
  695. * @return string
  696. */
  697. public function renderRegion($region)
  698. {
  699. return '';
  700. }
  701. /**
  702. * Returns true if the plugin is installed, false otherwise
  703. * @return bool True if plugin is installed/enabled, false otherwise
  704. */
  705. public function isEnabled()
  706. {
  707. $settings = api_get_settings_params_simple(
  708. array(
  709. "subkey = ? AND category = ? AND type = ? AND variable = 'status' " => array($this->get_name(), 'Plugins', 'setting')
  710. )
  711. );
  712. if (is_array($settings) && isset($settings['selected_value']) && $settings['selected_value'] == 'installed') {
  713. return true;
  714. }
  715. return false;
  716. }
  717. }