* Author: Aart-Jan Boor * Wemag Advisering * Website: http://www.ktplugins.com * * KTPUtil contains all kinds of functionality to make developing * plugins easier. * */ class KTPUtil{ /** * Checks if one or more database tables are present and shows an informative error page if a table is missing. Can be used to check * if a user has executed a SQL install script already. * @param array $tables array with database tables to check * @return */ public static function doDbTableCheck($tables){ foreach($tables as $table){ if(!KTPUtil::checkIfDatabaseTableExists($table)){ KTPUtil::displayError("The database table \"".$table."\", which is required to install this plugin, is not present in your DMS database. Please consult the plugin installation instructions on how to install this database table."); } } } /** * Check if a database table exists. * @param string $table * @return true if exists, false otherwise. */ public static function checkIfDatabaseTableExists($table) { $res = DBUtil::runQuery("SELECT * FROM $table"); if (PEAR::isError($res)) { return false; } return true; } /** * Show an error on a nicely formatted error page with a (partial) stack trace as optional debugging information. * @param string $msg Error message * @param boolean $suppressDebug [optional] if set to true no track trace is shown * @return */ public static function displayError($msg, $suppressDebug = false) { $error = $msg .= "

"; if($suppressDebug){ $trace = debug_backtrace(); foreach($trace as $t){ $msg .= $t['file']." - line ".$t['line']."
"; } $msg.="

"; } $_SESSION['ktp_error_msg'] = $msg; header("Location: ".KTUtil::kt_url()."/plugins/KTPFramework/error.php"); exit; } /** * Registers output trigger, see tutorial on http://www.ktplugins.com for more information. * @param string $plugin_namespace plugin namespace * @param string $class classname * @param string $file filename * @return */ public static function registerOutputTrigger($plugin_namespace,$class,$file){ return self::registerTrigger($plugin_namespace, "output", $class, $file); } /** * Registers admin output trigger, see tutorial on http://www.ktplugins.com for more information. * @param string $plugin_namespace plugin namespace * @param string $class classname * @param string $file filename * @return */ public static function registerAdminOutputTrigger($plugin_namespace,$class,$file){ return self::registerTrigger($plugin_namespace, "admin_output", $class, $file); } /** * Registers render trigger, see tutorial on http://www.ktplugins.com for more information. * @param string $plugin_namespace plugin namespace * @param string $class classname * @param string $file filename * @return */ public static function registerRenderTrigger($plugin_namespace,$class,$file){ return self::registerTrigger($plugin_namespace, "render", $class, $file); } /** * Registers admin render trigger, see tutorial on http://www.ktplugins.com for more information. * @param string $plugin_namespace plugin namespace * @param string $class classname * @param string $file filename * @return */ public static function registerAdminRenderTrigger($plugin_namespace,$class,$file){ return self::registerTrigger($plugin_namespace, "admin_render", $class, $file); } /** * Add a trigger which is launched when a portlet is added to the sidebar. * @param string $plugin_namespace plugin namespace * @param string $class classname * @param string $file filename * @return */ public static function registerAddPortletTrigger($plugin_namespace,$class,$file){ return self::registerTrigger($plugin_namespace, "add_portlet", $class, $file); } /** * Registers a trigger, use dedicated methods for each different type if possible. * @param object $plugin_namespace * @param object $type * @param object $class * @param object $file * @return */ public static function registerTrigger($plugin_namespace,$type,$class,$file){ $res = DBUtil::getResultArray("SELECT * FROM ktp_fw_triggers WHERE plugin = '".mysql_real_escape_string($plugin_namespace)."' AND type = '". mysql_real_escape_string($type)."' AND class = '".mysql_real_escape_string($class)."' AND file = '".mysql_real_escape_string($file)."'"); if(count($res) == 0){ $res = DBUtil::runQuery("INSERT INTO ktp_fw_triggers (plugin,type,class,file) VALUES ('".mysql_real_escape_string($plugin_namespace)."','".mysql_real_escape_string($type)."','". mysql_real_escape_string($class)."','".mysql_real_escape_string($file)."')"); return $res; } } } ?>