public function __construct() { if (isset($_SESSION['odinUserLogged'])) { Logger::getLogger('odin')->debug('User zalogowany'); } $this->db = PluginManager::getInstance()->getPlugin('creole')->getC(); }
function __construct($context, &$values = array(), &$args = array(), &$errors = array()) { //Notice: There's no difference in sending an empty $values array //or sending no value at all. Should this be detected? $action = $context->getAction(); if (!isset(self::$id_count[$action])) { self::$id_count[$action] = 0; } $this->_id = strtolower(get_class($this) . '_' . $action . '_' . ++self::$id_count[$action]); $this->_raw_value = (array) $values; $this->_context = $context; $this->args = (array) $args; $this->load = new Loader($context); $this->db = new DatabaseProxy($this->load); $this->plugin = PluginManager::getInstance()->getPluginList(); $this->lang = $this->load->lang(); $this->session = new Session($context->getModule()); $this->valid = $this->load->validator('/phaxsi/validator'); $this->helper = new HelperLoader($this->load); if (empty($this->_raw_value)) { if ($flash = Session::getFlash($this->_id)) { $this->_raw_value = $flash['values']; $this->_errors = $flash['errors']; } } if ($errors) { $this->_errors = array_merge((array) $this->_errors, $errors); } $create_method_ptr = array(&$this, $this->_context->getAction()); if (is_callable($create_method_ptr)) { call_user_func($create_method_ptr); } else { trigger_error("Form '" . $this->_context->getPath() . "' does not exist.", E_USER_ERROR); } }
public function trigger_automaticupdate_action($class) { $output = array(); if (Request::isPost()) { $plugin = PluginManager::getInstance()->getPluginInfo($class); $low_cost_secret = md5($GLOBALS['STUDIP_INSTALLATION_ID'] . $plugin['id']); if ($plugin['automatic_update_url'] && $low_cost_secret === \Request::option("s")) { if ($plugin['automatic_update_secret'] && !$this->verify_secret($plugin['automatic_update_secret'])) { $output['error'] = "Incorrect payload."; } else { //everything fine, we can download and install the plugin $update_url = $plugin['automatic_update_url']; require_once 'app/models/plugin_administration.php'; $plugin_admin = new PluginAdministration(); try { $plugin_admin->installPluginFromURL($update_url); } catch (Exception $e) { $output['exception'] = $e->getMessage(); } } } else { $output['error'] = "Wrong URL."; } if (!count($output)) { $output['message'] = "ok"; } } else { $output['error'] = "Only POST requests allowed."; } $this->render_json($output); }
protected function _render() { $manager = PluginManager::getInstance(); $manager->renderStart($this->context); $html = $this->view->render(); $manager->renderEnd($this->context); return $html; }
protected function display() { $this->smartyHelper->assign('activeGlobalMenuItem', 'Admin'); if (Tools::isConnectedUser()) { if (!$this->session_user->isTeamMember(Config::getInstance()->getValue(Config::id_adminTeamId))) { $this->smartyHelper->assign('accessDenied', TRUE); } else { $action = filter_input(INPUT_POST, 'action'); if (empty($action)) { $action = 'display'; } $pm = PluginManager::getInstance(); // === ACTIONS ===================================================== if ('enablePlugin' == $action) { $pluginName = Tools::getSecurePOSTStringValue('pluginName'); $pm->enablePlugin($pluginName); } else { if ('disablePlugin' == $action) { $pluginName = Tools::getSecurePOSTStringValue('pluginName'); $pm->disablePlugin($pluginName); } else { if ('discoverNewPlugins' == $action) { try { Tools::createClassMap(); $pm->discoverNewPlugins(); //$this->smartyHelper->assign('infoMsg', T_('Found xx new plugins !')); } catch (Exception $e) { $this->smartyHelper->assign('errorMsg', T_('Could not create classmap: ') . $e->getMessage()); } } } } // === DISPLAY ===================================================== // set values to display plugin table $plugins = $pm->getPlugins(); $formattedPlugins = array(); foreach ($plugins as $plugin) { $className = $plugin['className']; $formated_domains = array(); foreach ($plugin['domains'] as $domName) { array_push($formated_domains, T_($domName)); } //sort($formated_domains); $formated_categories = array(); foreach ($plugin['categories'] as $catName) { array_push($formated_categories, T_($catName)); } //sort($formated_categories); $formattedPlugins[$className] = array('name' => $plugin['displayedName'], 'status' => $plugin['status'], 'statusName' => pluginManager::getStatusName($plugin['status']), 'domains' => implode(',<br>', $formated_domains), 'categories' => implode(',<br>', $formated_categories), 'version' => $plugin['version'], 'description' => $plugin['description']); } $this->smartyHelper->assign('availablePlugins', $formattedPlugins); } } }
/** * gets enabled plugins for a given studygroup * * @param string id of a studygroup * * @return array enabled plugins */ function getEnabledPlugins($id) { $enabled = array(); $plugin_manager = PluginManager::getInstance(); $plugins = $plugin_manager->getPlugins('StandardPlugin'); // get all globally enabled plugins foreach ($plugins as $plugin) { $enabled[get_class($plugin)] = $plugin->isActivated($id); } return $enabled; }
public function details_action() { Navigation::activateItem("/admin/locations/sem_classes"); $modules = array('CoreOverview' => array('id' => "CoreOverview", 'name' => _("Kern-Übersicht"), 'enabled' => true), 'CoreAdmin' => array('id' => "CoreAdmin", 'name' => _("Kern-Verwaltung"), 'enabled' => true), 'CoreForum' => array('id' => "CoreForum", 'name' => _("Kern-Forum"), 'enabled' => true), 'CoreStudygroupAdmin' => array('id' => "CoreStudygroupAdmin", 'name' => _("Studiengruppen-Verwaltung"), 'enabled' => true), 'CoreDocuments' => array('id' => "CoreDocuments", 'name' => _("Kern-Dateibereich"), 'enabled' => true), 'CoreSchedule' => array('id' => "CoreSchedule", 'name' => _("Kern-Termine"), 'enabled' => true), 'CoreParticipants' => array('id' => "CoreParticipants", 'name' => _("Kern-Teilnehmer"), 'enabled' => true), 'CoreStudygroupParticipants' => array('id' => "CoreStudygroupParticipants", 'name' => _("Kern-Studiengruppen-Teilnehmer"), 'enabled' => true), 'CoreLiterature' => array('id' => "CoreLiterature", 'name' => _("Kern-Literatur"), 'enabled' => true), 'CoreScm' => array('id' => "CoreScm", 'name' => _("Kern-Freie-Informationen"), 'enabled' => true), 'CoreWiki' => array('id' => "CoreWiki", 'name' => _("Kern-Wiki"), 'enabled' => true), 'CoreResources' => array('id' => "CoreResources", 'name' => _("Kern-Ressourcen"), 'enabled' => true), 'CoreCalendar' => array('id' => "CoreCalendar", 'name' => _("Kern-Kalender"), 'enabled' => true), 'CoreElearningInterface' => array('id' => "CoreElearningInterface", 'name' => _("Kern-Lernmodule"), 'enabled' => true)); $plugin_infos = PluginManager::getInstance()->getPluginInfos("StandardPlugin"); foreach ($plugin_infos as $plugin_info) { $modules[$plugin_info['class']] = $plugin_info; } $this->modules = $modules; $this->sem_class = $GLOBALS['SEM_CLASS'][Request::get("id")]; $this->overview_url = $this->url_for("admin/sem_classes/overview"); }
/** * Check if the option needs to be displayed in settings. Recursively also * set all parents to displayed */ private function displayCheck() { // check if it is a category $catDisplay = $this->category != 0; // check if it is a plugin and if it is activated $pluginManager = PluginManager::getInstance(); $plugin = $pluginManager->getPluginInfoById($this->plugin); $pluginDisplay = $this->plugin == 0 || $pluginManager->isPluginActivatedForUser($this->plugin, $this->user_id) && $plugin['enabled']; // now check both if ($catDisplay && $pluginDisplay) { $this->setDisplayed(); } }
/** * Sets the navigation of this plugin. * * @deprecated */ function setNavigation(StudipPluginNavigation $navigation) { parent::setNavigation($navigation); // prepend copy of navigation to its sub navigation $item_names = array_keys($navigation->getSubNavigation()); $navigation_copy = clone $navigation; $navigation_copy->clearSubmenu(); $navigation_copy->freezeActivation(); $navigation->insertSubNavigation('self', $navigation_copy, $item_names[0]); $navigation->setTitle($this->getDisplayTitle()); // Check activation for user and display if appropriate. if (Navigation::hasItem('/profile') && is_object($this->getRequestedUser()) && $GLOBALS['perm']->have_profile_perm('user', $this->getRequestedUser()->getUserid()) && PluginManager::getInstance()->isPluginActivatedForUser($this->getPluginId(), $this->getRequestedUser()->getUserid())) { Navigation::addItem('/profile/' . $this->getPluginclassname(), $navigation); } }
static function to($url, $permanent = false) { $_POST = null; //Generalize this if (!preg_match("/^https?:/", $url)) { $url = UrlHelper::localized($url); } if ($permanent) { header("HTTP/1.1 301 Moved Permanently"); } PluginManager::getInstance()->onRedirect($url); Session::end(true); header('Location: ' . $url); exit; }
public static function getContentById($id) { $db = PluginManager::getInstance()->getPlugin('creole')->getC(); if ($id == -1) { $rs = $db->executeQuery('SELECT `object_id` FROM tree WHERE `left`="1"'); while ($rs->next()) { $id = $rs->getInt('object_id'); } } else { preg_match('/\\/(.*)/', $id, $matches); $id = $matches[1]; } $rs = $db->executeQuery('SELECT o.*, c.class_name FROM objects o, classes c WHERE o.id="' . $id . '" AND o.class = c.id'); return $rs; }
/** * **/ private function __construct($consumer_key, $template) { $this->template = $template; $this->router = new \Slim(); restore_error_handler(); // @see handleErrors() $this->permissions = new Permissions($consumer_key); // Get routes from plugins, default routes are also defined as fake plugins $default_routes = glob(dirname(__FILE__) . '/../routes/*.php'); foreach ($default_routes as $route) { $class_name = 'RestIP\\' . str_replace(' ', '', ucwords(str_replace('-', ' ', basename($route, '.php')))) . 'Route'; require_once $route; $router = new $class_name(); $router->routes($this); $this->descriptions = array_merge($this->descriptions, $router->describeRoutes()); } // Unfortunately, PluginEngine::sendMessage() discards the reference // to the router somewhere along the way so we need to iterate manually foreach (\PluginManager::getInstance()->getPlugins('APIPlugin') as $plugin) { $plugin->routes($this); $this->descriptions = array_merge($this->descriptions, $plugin->describeRoutes()); } }
public function hosts_action() { //init LernmarktplatzHost::thisOne(); $this->hosts = LernmarktplatzHost::findAll(); foreach ($this->hosts as $host) { if (strpos($host['public_key'], "\r") !== false) { $host['public_key'] = str_replace("\r", "", $host['public_key']); $host->store(); } } if (!function_exists("curl_init")) { PageLayout::postMessage(MessageBox::error(_("Ihr PHP hat kein aktiviertes cURL-Modul."))); } $plugin = PluginManager::getInstance()->getPluginInfo(get_class($this->plugin)); $plugin_roles = RolePersistence::getAssignedPluginRoles($plugin['id']); $nobody_allowed = false; foreach ($plugin_roles as $role) { if (strtolower($role->rolename) === "nobody") { $nobody_allowed = true; } } if (!$nobody_allowed) { PageLayout::postMessage(MessageBox::error(_("Dieses Plugin ist nicht für nobody freigegeben. Damit kann sich dieser Marktplatz nicht mit anderen Stud.IP verbinden."))); } //zufällig einen Host nach Neuigkeiten fragen: if (count($this->hosts) > 1) { $index = rand(0, count($this->hosts) - 1); while ($this->hosts[$index]->isMe()) { $index++; if ($index >= count($this->hosts)) { $index = 0; } } $this->askForHosts($this->hosts[$index]); } }
public function perform(IHttpContext $context, $params = null) { $tree = new Tree(); $db = PluginManager::getInstance()->getPlugin('creole')->getC(); if ($params[0] == null) { $rs = $db->executeQuery('SELECT t.object_id, o.* FROM tree t, objects o WHERE t.object_id = o.id AND depth = 2'); $ret = array(); while ($rs->next()) { $ret[] = $rs->getRow(); } return array('result' => $ret, 'type' => 'cat'); } else { if ($tree->hasChilds($params[0])) { $rs = $db->executeQuery('SELECT o.* FROM objects o LEFT JOIN tree t ON ( t.object_id = o.id ) WHERE t.parent_id =' . $params[0]); $ret = array(); while ($rs->next()) { $ret[] = $rs->getRow(); } return array('result' => $ret, 'type' => 'titles'); } else { $rs = $db->executeQuery('SELECT o.*, u.FirstName, u.LastName FROM objects o LEFT JOIN tree t ON ( t.object_id = o.id ) LEFT JOIN lum_user u ON (o.user_id = u.id) WHERE t.object_id =' . $params[0]); $ret = array(); while ($rs->next()) { $ret = $rs->getRow(); } return array('result' => $ret, 'type' => 'text'); } } }
function execute($query, $params) { if (!$this->pdo) { $this->connect(); } if (AppConfig::DEBUG_MODE) { $parsed_query = $this->parse($query, $params); PluginManager::getInstance()->queryStart($parsed_query); } $stm = $this->pdo->prepare($query); $success = $stm->execute($params); if (!$success) { $error_info = $stm->errorInfo(); trigger_error($error_info[2], E_USER_WARNING); return false; } if (AppConfig::DEBUG_MODE) { PluginManager::getInstance()->queryEnd($parsed_query); } return $stm; }
/** * Template for the list of links (<div id="linklist">) * This function fills all the necessary fields in the $PAGE for the template 'linklist.html' * * @param pageBuilder $PAGE pageBuilder instance. * @param LinkDB $LINKSDB LinkDB instance. */ function buildLinkList($PAGE, $LINKSDB) { // Used in templates $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; // Smallhash filter if (!empty($_SERVER['QUERY_STRING']) && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) { try { $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']); } catch (LinkNotFoundException $e) { $PAGE->render404($e->getMessage()); exit; } } else { // Filter links according search parameters. $privateonly = !empty($_SESSION['privateonly']); $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly); } // ---- Handle paging. $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; // Start index. $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); $link['timestamp'] = $date->getTimestamp(); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = index_url($_SERVER) . $link['url']; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags); $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm); $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchtermUrl . $searchtagsUrl; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchtermUrl . $searchtagsUrl; } $token = isLoggedIn() ? getToken() : ''; // Fill all template fields. $data = array('previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_term' => $searchterm, 'search_tags' => $searchtags, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); // FIXME! temporary fix - see #399. if (!empty($GLOBALS['pagetitle']) && count($linkDisp) == 1) { $data['pagetitle'] = $GLOBALS['pagetitle']; } $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
static function lookup($id) { //Assuming local ID is the only lookup used! $path = false; if ($id && is_numeric($id)) { $sql = 'SELECT install_path FROM ' . PLUGIN_TABLE . ' WHERE id=' . db_input($id); $path = db_result(db_query($sql)); } if ($path) { return PluginManager::getInstance($path); } }
function service($name) { $obj = null; switch ($name) { case 'db': $obj = new DatabaseProxy($this); break; case 'plugin': $obj = PluginManager::getInstance()->getPluginList(); break; case 'lang': $obj = $this->lang(); break; case 'session': $obj = new Session($this->context->getModule(false)); break; case 'helper': $obj = new HelperLoader($this); break; default: trigger_error("Trying to get invalid property '{$name}'", E_USER_WARNING); break; } return $obj; }
/** * The service method runs the gateway application. It deserializes the raw data passed into the constructor as an AmfPacket, handles the headers, * handles the messages as requests to services, and returns the responses from the services * It does not however handle output headers, gzip compression, etc. that is the job of the calling script * * @return <String> the serialized amf packet containg the service responses */ public function service(){ $filterManager = FilterManager::getInstance(); $defaultHandler = new AmfHandler(); $deserializedResponse = null; try{ PluginManager::getInstance()->loadPlugins($this->config->pluginsFolder, $this->config->pluginsConfig, $this->config->disabledPlugins); //call filter for filtering serialized incoming packet $this->rawInputData = $filterManager->callFilters(self::FILTER_SERIALIZED_REQUEST, $this->rawInputData); //call filter to get the deserializer $deserializer = $filterManager->callFilters(self::FILTER_DESERIALIZER, $defaultHandler, $this->contentType); //deserialize $deserializedRequest = $deserializer->deserialize($this->getData, $this->postData, $this->rawInputData); //call filter for filtering deserialized request $deserializedRequest = $filterManager->callFilters(self::FILTER_DESERIALIZED_REQUEST, $deserializedRequest); //create service router $serviceRouter = new ServiceRouter($this->config->serviceFolderPaths, $this->config->serviceNames2ClassFindInfo); //call filter to get the deserialized request handler $deserializedRequestHandler = $filterManager->callFilters(self::FILTER_DESERIALIZED_REQUEST_HANDLER, $defaultHandler, $this->contentType); //handle request $deserializedResponse = $deserializedRequestHandler->handleDeserializedRequest($deserializedRequest, $serviceRouter); //call filter for filtering the deserialized response $deserializedResponse = $filterManager->callFilters(self::FILTER_DESERIALIZED_RESPONSE, $deserializedResponse); }catch(Exception $exception){ //call filter to get the exception handler $exceptionHandler = $filterManager->callFilters(self::FILTER_EXCEPTION_HANDLER, $defaultHandler, $this->contentType); //handle exception $deserializedResponse = $exceptionHandler->handleException($exception); } //call filter to get the serializer $serializer = $filterManager->callFilters(self::FILTER_SERIALIZER, $defaultHandler, $this->contentType); //serialize $this->rawOutputData = $serializer->serialize($deserializedResponse); //call filter for filtering the serialized response packet $this->rawOutputData = $filterManager->callFilters(self::FILTER_SERIALIZED_RESPONSE, $this->rawOutputData); return $this->rawOutputData; }
/** * Outputs links after bulk plugin installation is complete. */ public function bulk_footer() { /** Serve up the string to say installations (and possibly activations) are complete */ parent::bulk_footer(); /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); /** Display message based on if all plugins are now active or not */ $complete = array(); foreach (PluginManager::getInstance()->plugins as $plugin) { if (!is_plugin_active($plugin['file_path'])) { echo '<p><a href="' . add_query_arg('page', PluginManager::getInstance()->menu, admin_url(PluginManager::getInstance()->parent_url_slug)) . '" title="' . esc_attr(PluginManager::getInstance()->strings['return']) . '" target="_parent">' . __(PluginManager::getInstance()->strings['return'], PluginManager::TEXT_DOMAIN) . '</a></p>'; $complete[] = $plugin; break; } else { $complete[] = ''; } } /** Filter out any empty entries */ $complete = array_filter($complete); /** All plugins are active, so we display the complete string and hide the menu to protect users */ if (empty($complete)) { echo '<p>' . sprintf(PluginManager::getInstance()->strings['complete'], '<a href="' . admin_url() . '" title="' . __('Return to the Dashboard', PluginManager::TEXT_DOMAIN) . '">' . __('Return to the Dashboard', PluginManager::TEXT_DOMAIN) . '</a>') . '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } }
public function getSmartyVariables($smartyHelper) { // dashboard settings $pm = PluginManager::getInstance(); $candidates = $pm->getPluginCandidates($this->domain, $this->categories); // user specific dashboard settings if (NULL == $this->settings) { $this->getSettings(); } // insert widgets $pluginDataProvider = PluginDataProvider::getInstance(); $idx = 1; $dashboardPluginCssFiles = array(); $dashboardPluginJsFiles = array(); foreach ($this->settings[self::SETTINGS_DISPLAYED_PLUGINS] as $pluginAttributes) { $pClassName = $pluginAttributes['pluginClassName']; try { // check that this plugin is allowed to be displayed in this dashboard if (!in_array($pClassName, $candidates)) { self::$logger->error("Dashboard user settings: " . $pClassName . ' is not a candidate !'); continue; } $widget = self::getWidget($pluginDataProvider, $smartyHelper, $pluginAttributes, $idx); $dashboardWidgets[$pClassName] = $widget; // get all mandatory CSS files foreach ($pClassName::getCssFiles() as $cssFile) { if (!in_array($cssFile, $dashboardPluginCssFiles)) { array_push($dashboardPluginCssFiles, $cssFile); } } // get all mandatory JS files foreach ($pClassName::getJsFiles() as $jsFile) { if (!in_array($jsFile, $dashboardPluginJsFiles)) { array_push($dashboardPluginJsFiles, $jsFile); } } $idx += 1; } catch (Exception $e) { self::$logger->error('Could not display plugin ' . $pClassName . ': ' . $e->getMessage()); } } // TODO as long as adding multiple times the same plugin fails, // the dilplayedPlugins should be removed from candidates $dashboardPluginCandidates = array(); foreach ($candidates as $cClassName) { if (class_exists($cClassName)) { $categories = $cClassName::getCategories(); $dashboardPluginCandidates[] = array('pluginClassName' => $cClassName, 'title' => $cClassName::getName(), 'category' => $categories[0]); } else { self::$logger->error('Could not display plugin ' . $cClassName . ': class not found'); } } return array('dashboardId' => $this->id, 'dashboardTitle' => 'title', 'dashboardPluginCandidates' => $dashboardPluginCandidates, 'dashboardWidgets' => $dashboardWidgets, 'dashboardPluginCssFiles' => $dashboardPluginCssFiles, 'dashboardPluginJsFiles' => $dashboardPluginJsFiles); }
/** * Performs the actual installation of each plugin. * * This method also activates the plugin in the automatic flag has been * set to true for the TGMPA class. * * @param array $options The installation cofig options * @return null/array Return early if error, array of installation data on success */ public function run($options) { /** Default config options */ $defaults = array('package' => '', 'destination' => '', 'clear_destination' => false, 'clear_working' => true, 'is_multi' => false, 'hook_extra' => array()); /** Parse default options with config options from $this->bulk_upgrade and extract them */ $options = wp_parse_args($options, $defaults); extract($options); /** Connect to the Filesystem */ $res = $this->fs_connect(array(WP_CONTENT_DIR, $destination)); if (!$res) { return false; } /** Return early if there is an error connecting to the Filesystem */ if (is_wp_error($res)) { $this->skin->error($res); return $res; } /** Call $this->header separately if running multiple times */ if (!$is_multi) { $this->skin->header(); } /** Set strings before the package is installed */ $this->skin->before(); /** Download the package (this just returns the filename of the file if the package is a local file) */ $download = $this->download_package($package); if (is_wp_error($download)) { $this->skin->error($download); $this->skin->after(); return $download; } /** Don't accidentally delete a local file */ $delete_package = $download != $package; /** Unzip file into a temporary working directory */ $working_dir = $this->unpack_package($download, $delete_package); if (is_wp_error($working_dir)) { $this->skin->error($working_dir); $this->skin->after(); return $working_dir; } /** Install the package into the working directory with all passed config options */ $result = $this->install_package(array('source' => $working_dir, 'destination' => $destination, 'clear_destination' => $clear_destination, 'clear_working' => $clear_working, 'hook_extra' => $hook_extra)); /** Pass the result of the installation */ $this->skin->set_result($result); /** Set correct strings based on results */ if (is_wp_error($result)) { $this->skin->error($result); $this->skin->feedback('process_failed'); } else { $this->skin->feedback('process_success'); } /** Only process the activation of installed plugins if the automatic flag is set to true */ if (PluginManager::getInstance()->is_automatic) { /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); /** Get the installed plugin file and activate it */ $plugin_info = $this->plugin_info($package); $activate = activate_plugin($plugin_info); /** Re-populate the file path now that the plugin has been installed and activated */ PluginManager::getInstance()->populate_file_path(); /** Set correct strings based on results */ if (is_wp_error($activate)) { $this->skin->error($activate); $this->skin->feedback('activation_failed'); } else { $this->skin->feedback('activation_success'); } } /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); /** Set install footer strings */ $this->skin->after(); if (!$is_multi) { $this->skin->footer(); } return $result; }
function insertPluginMarkers ($plugin_type, &$markers, $element_name) { $plugin_manager = PluginManager::getInstance(); foreach ($plugin_manager->getPluginInfos($plugin_type) as $plugin) { $keyname = 'PLUGIN_' . strtoupper($plugin['name']); $markers[$element_name][] = array("###$keyname###", $plugin['description']); } }
function buildLinkList($PAGE, $LINKSDB) { // ---- Filter link database according to parameters $linksToDisplay = array(); $search_type = ''; $search_crits = ''; if (isset($_GET['searchterm'])) { $linksToDisplay = $LINKSDB->filterFulltext(trim($_GET['searchterm'])); $search_crits = escape(trim($_GET['searchterm'])); $search_type = 'fulltext'; } elseif (isset($_GET['searchtags'])) { $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); $search_crits = explode(' ', escape(trim($_GET['searchtags']))); $search_type = 'tags'; } elseif (isset($_SERVER['QUERY_STRING']) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) { $linksToDisplay = $LINKSDB->filterSmallHash(substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6)); if (count($linksToDisplay) == 0) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.'; echo '<br>Would you mind <a href="?">clicking here</a>?'; exit; } $search_type = 'permalink'; } else { $linksToDisplay = $LINKSDB; } // Otherwise, display without filtering. // Option: Show only private links if (!empty($_SESSION['privateonly'])) { $tmp = array(); foreach ($linksToDisplay as $linkdate => $link) { if ($link['private'] != 0) { $tmp[$linkdate] = $link; } } $linksToDisplay = $tmp; } // ---- Handle paging. /* Can someone explain to me why you get the following error when using array_keys() on an object which implements the interface ArrayAccess??? "Warning: array_keys() expects parameter 1 to be array, object given in ... " If my class implements ArrayAccess, why won't array_keys() accept it ? ( $keys=array_keys($linksToDisplay); ) */ $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // Stupid and ugly. Thanks PHP. // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; // Start index. $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); // Links to display while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $link['timestamp'] = linkdate2timestamp($link['linkdate']); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); if ($link["url"][0] === '?' && strlen($link["url"]) === 7) { $link["url"] = index_url($_SERVER) . $link["url"]; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm']; $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags']; $paging = ''; $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchterm . $searchtags; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchterm . $searchtags; } $token = ''; if (isLoggedIn()) { $token = getToken(); } // Fill all template fields. $data = array('pagetitle' => $GLOBALS['pagetitle'], 'linkcount' => count($LINKSDB), 'previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_type' => $search_type, 'search_crits' => $search_crits, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
static protected function getActivityTables() { $tables = array(); $tables[] = array('table' => "user_info"); $tables[] = array('table' => "comments"); $tables[] = array('table' => "dokumente"); $tables[] = array('table' => "forum_entries"); $tables[] = array('table' => "news"); $tables[] = array('table' => "seminar_user"); $tables[] = array( 'table' => "blubber", 'where' => "context_type != 'private'" ); $tables[] = array( 'table' => "kategorien", 'user_id_column' => "range_id" ); $tables[] = array( 'table' => "message", 'user_id_column' => "autor_id" ); $tables[] = array( 'table' => "questionnaires" ); $tables[] = array( 'table' => "questionnaire_answers", 'date_column' => "chdate" ); $tables[] = array( 'table' => "questionnaire_anonymous_answers" ); $tables[] = array( 'table' => "wiki", 'date_column' => "chdate" ); foreach (PluginManager::getInstance()->getPlugins("ScorePlugin") as $plugin) { foreach ((array) $plugin->getPluginActivityTables() as $table) { if ($table['table']) { $tables[] = $table; } } } return $tables; }
/** * getWidget - retrieves an instance of a given widget / portal plugin * * @param string $pluginid * * @return object widget */ static function getWidget($pluginid) { return PluginManager::getInstance()->getPluginById($pluginid); }
/** * updates studygroups with respect to the corresponding form data * * @param string id of a studygroup * * @return void */ function update_action($id) { global $perm; // if we are permitted to edit the studygroup get some data... if ($perm->have_studip_perm('dozent', $id)) { $errors = array(); $admin = $perm->have_studip_perm('admin', $id); $founders = StudygroupModel::getFounders($id); $sem = new Seminar($id); $sem_class = $GLOBALS['SEM_CLASS'][$GLOBALS['SEM_TYPE'][$sem->status]['class']]; CSRFProtection::verifyUnsafeRequest(); if (Request::get('abort_deactivate')) { // let's do nothing and go back to the studygroup return $this->redirect('course/studygroup/edit/' . $id); } else { if (Request::get('really_deactivate')) { $modules = Request::optionArray('deactivate_modules'); $plugins = Request::optionArray('deactivate_plugins'); // really deactive modules // 1. Modules if (is_array($modules)) { $mods = new Modules(); $admin_mods = new AdminModules(); $bitmask = $sem->modules; foreach ($modules as $key) { $module_name = $sem_class->getSlotModule($key); if ($module_name && ($sem_class->isModuleMandatory($module_name) || !$sem_class->isModuleAllowed($module_name))) { continue; } $mods->clearBit($bitmask, $mods->registered_modules[$key]["id"]); $methodDeactivate = "module" . ucfirst($key) . "Deactivate"; if (method_exists($admin_mods, $methodDeactivate)) { $admin_mods->{$methodDeactivate}($sem->id); $studip_module = $sem_class->getModule($key); if (is_a($studip_module, "StandardPlugin")) { PluginManager::getInstance()->setPluginActivated($studip_module->getPluginId(), $id, false); } } } $sem->modules = $bitmask; $sem->store(); } // 2. Plugins if (is_array($plugins)) { $plugin_manager = PluginManager::getInstance(); $available_plugins = StudygroupModel::getInstalledPlugins(); foreach ($plugins as $class) { $plugin = $plugin_manager->getPlugin($class); // Deaktiviere Plugin if ($available_plugins[$class] && !$sem_class->isModuleMandatory($class) && !$sem_class->isSlotModule($class)) { $plugin_manager->setPluginActivated($plugin->getPluginId(), $id, false); } } } // Success message $this->flash['success'] .= _("Inhaltselement(e) erfolgreich deaktiviert."); return $this->redirect('course/studygroup/edit/' . $id); } else { if (Request::submitted('replace_founder')) { // retrieve old founder $old_dozent = current(StudygroupModel::getFounder($id)); // remove old founder StudygroupModel::promote_user($old_dozent['uname'], $id, 'tutor'); // add new founder $new_founder = Request::option('choose_founder'); StudygroupModel::promote_user(get_username($new_founder), $id, 'dozent'); //checks } else { // test whether we have a group name... if (!Request::get('groupname')) { $errors[] = _("Bitte Gruppennamen angeben"); //... if so, test if this is not taken by another group } else { $query = "SELECT 1 FROM seminare WHERE name = ? AND Seminar_id != ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array(Request::get('groupname'), $id)); if ($statement->fetchColumn()) { $errors[] = _("Eine Veranstaltung/Studiengruppe mit diesem Namen existiert bereits. Bitte wählen Sie einen anderen Namen"); } } if (count($errors)) { $this->flash['errors'] = $errors; $this->flash['edit'] = true; // Everything seems fine, let's update the studygroup } else { $sem->name = Request::get('groupname'); // seminar-class quotes itself $sem->description = Request::get('groupdescription'); // seminar-class quotes itself $sem->read_level = 1; $sem->write_level = 1; $sem->visible = 1; if (Request::get('groupaccess') == 'all') { $sem->admission_prelim = 0; } else { $sem->admission_prelim = 1; if (Config::get()->STUDYGROUPS_INVISIBLE_ALLOWED && Request::get('groupaccess') == 'invisible') { $sem->visible = 0; } $sem->admission_prelim_txt = _("Die ModeratorInnen der Studiengruppe können Ihren Aufnahmewunsch bestätigen oder ablehnen. Erst nach Bestätigung erhalten Sie vollen Zugriff auf die Gruppe."); } // get the current bitmask $mods = new Modules(); $admin_mods = new AdminModules(); $bitmask = $sem->modules; // de-/activate modules $available_modules = StudygroupModel::getInstalledModules(); $orig_modules = $mods->getLocalModules($sem->id, "sem"); $active_plugins = Request::getArray("groupplugin"); $deactivate_modules = array(); foreach (array_keys($available_modules) as $key) { $module_name = $sem_class->getSlotModule($key); if (!$module_name || $module_name && ($sem_class->isModuleMandatory($module_name) || !$sem_class->isModuleAllowed($module_name))) { continue; } if (!$module_name) { $module_name = $key; } if ($active_plugins[$module_name]) { // activate modules $mods->setBit($bitmask, $mods->registered_modules[$key]["id"]); if (!$orig_modules[$key]) { $methodActivate = "module" . ucfirst($key) . "Activate"; if (method_exists($admin_mods, $methodActivate)) { $admin_mods->{$methodActivate}($sem->id); $studip_module = $sem_class->getModule($key); if (is_a($studip_module, "StandardPlugin")) { PluginManager::getInstance()->setPluginActivated($studip_module->getPluginId(), $id, true); } } } } else { // prepare for deactivation // (user will have to confirm) if ($orig_modules[$key]) { $deactivate_modules[] = $key; } } } $this->flash['deactivate_modules'] = $deactivate_modules; $sem->modules = $bitmask; $sem->store(); // de-/activate plugins $available_plugins = StudygroupModel::getInstalledPlugins(); $plugin_manager = PluginManager::getInstance(); $deactivate_plugins = array(); foreach ($available_plugins as $key => $name) { $plugin = $plugin_manager->getPlugin($key); $plugin_id = $plugin->getPluginId(); if ($active_plugins[$key] && $name && $sem_class->isModuleAllowed($key)) { $plugin_manager->setPluginActivated($plugin_id, $id, true); } else { if ($plugin_manager->isPluginActivated($plugin_id, $id) && !$sem_class->isSlotModule($key)) { $deactivate_plugins[$plugin_id] = $key; } } } $this->flash['deactivate_plugins'] = $deactivate_plugins; } } } } } if (!$this->flash['errors'] && !$deactivate_modules && !$deactivate_plugins) { // Everything seems fine $this->flash['success'] = _("Die Änderungen wurden erfolgreich übernommen."); } // let's go to the studygroup $this->redirect('course/studygroup/edit/' . $id); }
function buildLinkList($PAGE, $LINKSDB) { // ---- Filter link database according to parameters $search_type = ''; $search_crits = ''; $privateonly = !empty($_SESSION['privateonly']) ? true : false; // Fulltext search if (isset($_GET['searchterm'])) { $search_crits = escape(trim($_GET['searchterm'])); $search_type = LinkFilter::$FILTER_TEXT; $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); } elseif (isset($_GET['searchtags'])) { $search_crits = explode(' ', escape(trim($_GET['searchtags']))); $search_type = LinkFilter::$FILTER_TAG; $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); } elseif (isset($_SERVER['QUERY_STRING']) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) { $search_type = LinkFilter::$FILTER_HASH; $search_crits = substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6); $linksToDisplay = $LINKSDB->filter($search_type, $search_crits); if (count($linksToDisplay) == 0) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.'; echo '<br>Would you mind <a href="?">clicking here</a>?'; exit; } } else { $linksToDisplay = $LINKSDB->filter('', '', false, $privateonly); } // ---- Handle paging. $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; // Start index. $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $link['timestamp'] = linkdate2timestamp($link['linkdate']); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = index_url($_SERVER) . $link['url']; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm']; $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags']; $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchterm . $searchtags; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchterm . $searchtags; } $token = ''; if (isLoggedIn()) { $token = getToken(); } // Fill all template fields. $data = array('linkcount' => count($LINKSDB), 'previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_type' => $search_type, 'search_crits' => $search_crits, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); // FIXME! temporary fix - see #399. if (!empty($GLOBALS['pagetitle']) && count($linkDisp) == 1) { $data['pagetitle'] = $GLOBALS['pagetitle']; } $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
/** * Processes bulk installation and activation actions. * * The bulk installation process looks either for the $_POST * information or for the plugin info within the $_GET variable if * a user has to use WP_Filesystem to enter their credentials. */ public function process_bulk_actions() { /** Bulk installation process */ if ('tgmpa-bulk-install' === $this->current_action()) { check_admin_referer('bulk-' . $this->_args['plural']); /** Prep variables to be populated */ $plugins_to_install = array(); $plugin_installs = array(); $plugin_path = array(); $plugin_name = array(); /** Look first to see if information has been passed via WP_Filesystem */ if (isset($_GET[sanitize_key('plugins')])) { $plugins = explode(',', stripslashes($_GET[sanitize_key('plugins')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugins = (array) $_POST[sanitize_key('plugin')]; } else { $plugins = array(); } $a = 0; // Incremental variable /** Grab information from $_POST if available */ if (isset($_POST[sanitize_key('plugin')])) { foreach ($plugins as $plugin_data) { $plugins_to_install[] = explode(',', $plugin_data); } foreach ($plugins_to_install as $plugin_data) { $plugin_installs[] = $plugin_data[0]; $plugin_path[] = $plugin_data[1]; $plugin_name[] = $plugin_data[2]; } } else { foreach ($plugins as $key => $value) { /** Grab plugin slug for each plugin */ if (0 == $key % 3 || 0 == $key) { $plugins_to_install[] = $value; $plugin_installs[] = $value; } $a++; } } /** Look first to see if information has been passed via WP_Filesystem */ if (isset($_GET[sanitize_key('plugin_paths')])) { $plugin_paths = explode(',', stripslashes($_GET[sanitize_key('plugin_paths')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugin_paths = (array) $plugin_path; } else { $plugin_paths = array(); } /** Look first to see if information has been passed via WP_Filesystem */ if (isset($_GET[sanitize_key('plugin_names')])) { $plugin_names = explode(',', stripslashes($_GET[sanitize_key('plugin_names')])); } elseif (isset($_POST[sanitize_key('plugin')])) { $plugin_names = (array) $plugin_name; } else { $plugin_names = array(); } $b = 0; // Incremental variable /** Loop through plugin slugs and remove already installed plugins from the list */ foreach ($plugin_installs as $key => $plugin) { if (preg_match('|.php$|', $plugin)) { unset($plugin_installs[$key]); /** If the plugin path isn't in the $_GET variable, we can unset the corresponding path */ if (!isset($_GET[sanitize_key('plugin_paths')])) { unset($plugin_paths[$b]); } /** If the plugin name isn't in the $_GET variable, we can unset the corresponding name */ if (!isset($_GET[sanitize_key('plugin_names')])) { unset($plugin_names[$b]); } } $b++; } /** No need to proceed further if we have no plugins to install */ if (empty($plugin_installs)) { return false; } /** Reset array indexes in case we removed already installed plugins */ $plugin_installs = array_values($plugin_installs); $plugin_paths = array_values($plugin_paths); $plugin_names = array_values($plugin_names); /** If we grabbed our plugin info from $_GET, we need to decode it for use */ $plugin_installs = array_map('urldecode', $plugin_installs); $plugin_paths = array_map('urldecode', $plugin_paths); $plugin_names = array_map('urldecode', $plugin_names); /** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url(add_query_arg(array('page' => PluginManager::getInstance()->menu, 'tgmpa-action' => 'install-selected', 'plugins' => urlencode(implode(',', $plugins)), 'plugin_paths' => urlencode(implode(',', $plugin_paths)), 'plugin_names' => urlencode(implode(',', $plugin_names))), admin_url(PluginManager::getInstance()->parent_url_slug)), 'bulk-plugins'); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array(sanitize_key('action'), sanitize_key('_wp_http_referer'), sanitize_key('_wpnonce')); // Extra fields to pass to WP_Filesystem if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) { return true; } if (!WP_Filesystem($creds)) { request_filesystem_credentials($url, $method, true, false, $fields); // Setup WP_Filesystem return true; } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes $api = array(); $sources = array(); $install_path = array(); $c = 0; // Incremental variable /** Loop through each plugin to install and try to grab information from WordPress API, if not create 'tgmpa-empty' scalar */ foreach ($plugin_installs as $plugin) { $api[$c] = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) ? plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false))) : (object) ($api[$c] = 'tgmpa-empty'); $c++; } if (is_wp_error($api)) { wp_die(PluginManager::getInstance()->strings['oops'] . var_dump($api)); } $d = 0; // Incremental variable /** Capture download links from $api or set install link to pre-packaged/private repo */ foreach ($api as $object) { $sources[$d] = isset($object->download_link) && 'repo' == $plugin_paths[$d] ? $object->download_link : $plugin_paths[$d]; $d++; } /** Finally, all the data is prepared to be sent to the installer */ $url = add_query_arg(array('page' => PluginManager::getInstance()->menu), admin_url(PluginManager::getInstance()->parent_url_slug)); $nonce = 'bulk-plugins'; $names = $plugin_names; /** Create a new instance of TGM_Bulk_Installer */ $installer = new BulkInstaller($skin = new BulkInstallerSkin(compact('url', 'nonce', 'names'))); /** Wrap the install process with the appropriate HTML */ echo '<div class="tgmpa wrap">'; screen_icon(apply_filters('tgmpa_default_screen_icon', 'themes')); echo '<h2>' . esc_html(get_admin_page_title()) . '</h2>'; /** Process the bulk installation submissions */ $installer->bulk_install($sources); echo '</div>'; return true; } /** Bulk activation process */ if ('tgmpa-bulk-activate' === $this->current_action()) { check_admin_referer('bulk-' . $this->_args['plural']); /** Grab plugin data from $_POST */ $plugins = isset($_POST[sanitize_key('plugin')]) ? (array) $_POST[sanitize_key('plugin')] : array(); $plugins_to_activate = array(); /** Split plugin value into array with plugin file path, plugin source and plugin name */ foreach ($plugins as $i => $plugin) { $plugins_to_activate[] = explode(',', $plugin); } foreach ($plugins_to_activate as $i => $array) { if (!preg_match('|.php$|', $array[0])) { // Plugins that haven't been installed yet won't have the correct file path unset($plugins_to_activate[$i]); } } /** Return early if there are no plugins to activate */ if (empty($plugins_to_activate)) { return; } $plugins = array(); $plugin_names = array(); foreach ($plugins_to_activate as $plugin_string) { $plugins[] = $plugin_string[0]; $plugin_names[] = $plugin_string[2]; } $count = count($plugin_names); // Count so we can use _n function $last_plugin = array_pop($plugin_names); // Pop off last name to prep for readability $imploded = empty($plugin_names) ? '<strong>' . $last_plugin . '</strong>' : '<strong>' . (implode(', ', $plugin_names) . '</strong> and <strong>' . $last_plugin . '</strong>.'); /** Now we are good to go - let's start activating plugins */ $activate = activate_plugins($plugins); if (is_wp_error($activate)) { echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>'; } else { printf('<div id="message" class="updated"><p>%1$s %2$s</p></div>', _n('The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, PluginManager::TEXT_DOMAIN), $imploded); } /** Update recently activated plugins option */ $recent = (array) get_option('recently_activated'); foreach ($plugins as $plugin => $time) { if (isset($recent[$plugin])) { unset($recent[$plugin]); } } update_option('recently_activated', $recent); unset($_POST); // Reset the $_POST variable in case user wants to perform one action after another } }
/** * Returns all Seminar_ids to courses I am member of and in which blubber * is an active plugin. * @return array of string : array of Seminar_ids */ protected function getMyCourses() { if ($GLOBALS['perm']->have_perm("admin", $this->user_id)) { return array(); } $mandatory_classes = array(); $standard_classes = array(); $forbidden_classes = array(); $mandatory_types = array(); $standard_types = array(); $forbidden_types = array(); foreach (SemClass::getClasses() as $key => $class) { $blubber_setting = $class->getModuleMetadata("Blubber"); if ($class->isModuleMandatory("Blubber")) { $mandatory_classes[] = $key; } if ($class->isSlotModule("Blubber") or $blubber_setting['activated'] && !$blubber_setting['sticky']) { $standard_classes[] = $key; } if (!$class->isModuleAllowed("Blubber")) { $forbidden_classes[] = $key; } } foreach (SemType::getTypes() as $key => $type) { if (in_array($type['class'], $mandatory_classes)) { $mandatory_types[] = $key; } if (in_array($type['class'], $standard_classes)) { $standard_types[] = $key; } if (in_array($type['class'], $forbidden_classes)) { $forbidden_types[] = $key; } } $is_deputy = get_config('DEPUTIES_ENABLE') && DBManager::get()->fetchColumn("SELECT 1 FROM deputies WHERE user_id=? LIMIT 1", array($this->user_id)); $blubber_plugin_info = PluginManager::getInstance()->getPluginInfo('Blubber'); $statement = DBManager::get()->prepare("\r\n SELECT seminare.Seminar_id\r\n FROM seminar_user\r\n INNER JOIN seminare ON (seminare.Seminar_id = seminar_user.Seminar_id)\r\n WHERE seminar_user.user_id = :me\r\n AND seminare.status IN (:mandatory_types)\r\n AND seminare.status NOT IN (:forbidden_types)\r\n\r\n UNION DISTINCT SELECT seminare.Seminar_id\r\n FROM seminar_user\r\n INNER JOIN seminare ON (seminare.Seminar_id = seminar_user.Seminar_id)\r\n INNER JOIN plugins_activated ON (pluginid = :blubber_plugin_id\r\n AND plugins_activated.poiid = CONCAT('sem', seminare.Seminar_id))\r\n WHERE seminar_user.user_id = :me\r\n AND plugins_activated.state = 'on'\r\n AND seminare.status NOT IN (:forbidden_types)\r\n\r\n UNION DISTINCT SELECT seminare.Seminar_id\r\n FROM seminar_user\r\n INNER JOIN seminare ON (seminare.Seminar_id = seminar_user.Seminar_id)\r\n LEFT JOIN plugins_activated ON (pluginid = :blubber_plugin_id\r\n AND plugins_activated.poiid = CONCAT('sem', seminare.Seminar_id))\r\n WHERE seminar_user.user_id = :me\r\n AND plugins_activated.state IS NULL\r\n AND seminare.status NOT IN (:forbidden_types)\r\n "); $parameter = array('me' => $this->user_id); $parameter['mandatory_types'] = count($mandatory_types) ? $mandatory_types : null; $parameter['standard_types'] = count($standard_types) ? $standard_types : null; $parameter['forbidden_types'] = count($forbidden_types) ? $forbidden_types : array(-1); $parameter['blubber_plugin_id'] = $blubber_plugin_info['id']; $statement->execute($parameter); $my_courses = $statement->fetchFirst(); if ($is_deputy) { $statement = DBManager::get()->prepare("SELECT deputies.range_id " . "FROM deputies " . "INNER JOIN seminare ON (seminare.Seminar_id = deputies.range_id) " . "LEFT JOIN plugins_activated ON (pluginid = :blubber_plugin_id AND plugins_activated.poiid = CONCAT('sem', seminare.Seminar_id)) " . "WHERE deputies.user_id = :me " . "AND (" . "seminare.status IN (:mandatory_types) " . "OR (plugins_activated.state = 'on') " . "OR (seminare.status IN (:standard_types) AND plugins_activated.state != 'off') " . ") " . "AND seminare.status NOT IN (:forbidden_types) " . ""); $statement->execute($parameter); $my_courses = array_merge($my_courses, $statement->fetchFirst()); } return $my_courses; }