/** * Get list of components available * * @since 2.0 */ public function get_components() { $components = pods_transient_get('pods_components'); if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { $components = array(); } if (PodsInit::$version != PODS_VERSION || !is_array($components) || empty($components) || is_admin() && isset($_GET['page']) && 'pods-components' == $_GET['page'] && 1 !== pods_transient_get('pods_components_refresh')) { do_action('pods_components_get'); $component_dir = @opendir(untrailingslashit($this->components_dir)); $component_files = array(); if (false !== $component_dir) { while (false !== ($file = readdir($component_dir))) { if ('.' == substr($file, 0, 1)) { continue; } elseif (is_dir($this->components_dir . $file)) { $component_subdir = @opendir($this->components_dir . $file); if ($component_subdir) { while (false !== ($subfile = readdir($component_subdir))) { if ('.' == substr($subfile, 0, 1)) { continue; } elseif ('.php' == substr($subfile, -4)) { $component_files[] = str_replace('\\', '/', $file . '/' . $subfile); } } closedir($component_subdir); } } elseif ('.php' == substr($file, -4)) { $component_files[] = $file; } } closedir($component_dir); } $default_headers = array('ID' => 'ID', 'Name' => 'Name', 'ShortName' => 'Short Name', 'PluginName' => 'Plugin Name', 'ComponentName' => 'Component Name', 'URI' => 'URI', 'MenuName' => 'Menu Name', 'MenuPage' => 'Menu Page', 'MenuAddPage' => 'Menu Add Page', 'MustUse' => 'Must Use', 'Description' => 'Description', 'Version' => 'Version', 'Category' => 'Category', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Class' => 'Class', 'Hide' => 'Hide', 'PluginDependency' => 'Plugin Dependency', 'ThemeDependency' => 'Theme Dependency', 'DeveloperMode' => 'Developer Mode', 'TablelessMode' => 'Tableless Mode', 'Capability' => 'Capability', 'Plugin' => 'Plugin'); $component_files = apply_filters('pods_components_register', $component_files); $components = array(); foreach ($component_files as $component_file) { $external = false; if (is_array($component_file) && isset($component_file['File'])) { $component = $component_file = $component_file['File']; $external = true; } else { $component = $this->components_dir . $component_file; } if (!is_readable($component)) { continue; } $component_data = get_file_data($component, $default_headers, 'pods_component'); if (empty($component_data['Name']) && empty($component_data['ComponentName']) && empty($component_data['PluginName']) || 'yes' == $component_data['Hide']) { continue; } if (isset($component_data['Plugin']) && pods_is_plugin_active($component_data['Plugin'])) { continue; } if (empty($component_data['Name'])) { if (!empty($component_data['ComponentName'])) { $component_data['Name'] = $component_data['ComponentName']; } elseif (!empty($component_data['PluginName'])) { $component_data['Name'] = $component_data['PluginName']; } } if (empty($component_data['ShortName'])) { $component_data['ShortName'] = $component_data['Name']; } if (empty($component_data['MenuName'])) { $component_data['MenuName'] = $component_data['Name']; } if (empty($component_data['Class'])) { $component_data['Class'] = 'Pods_' . pods_clean_name(basename($component, '.php'), false); } if (empty($component_data['ID'])) { $component_data['ID'] = $component_data['Name']; } $component_data['ID'] = sanitize_title($component_data['ID']); if ('on' == strtolower($component_data['DeveloperMode']) || 1 == $component_data['DeveloperMode']) { $component_data['DeveloperMode'] = true; } else { $component_data['DeveloperMode'] = false; } if ('on' == strtolower($component_data['TablelessMode']) || 1 == $component_data['TablelessMode']) { $component_data['TablelessMode'] = true; } else { $component_data['TablelessMode'] = false; } $component_data['External'] = (bool) $external; if ('on' == strtolower($component_data['MustUse']) || '1' == $component_data['MustUse']) { $component_data['MustUse'] = true; } elseif ('off' == strtolower($component_data['MustUse']) || '0' == $component_data['MustUse']) { $component_data['MustUse'] = false; } else { $component_data['MustUse'] = $component_data['External']; } $component_data['File'] = $component_file; $components[$component_data['ID']] = $component_data; } ksort($components); pods_transient_set('pods_components_refresh', 1, 60 * 60 * 12); pods_transient_set('pods_components', $components); } if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($components); } $this->components = $components; return $this->components; }
/** * Toggle a component on or off * * @param PodsUI $ui * * @return bool */ public function admin_components_toggle(PodsUI $ui) { $component = $_GET['id']; if (!empty(PodsInit::$components->components[$component]['PluginDependency'])) { $dependency = explode('|', PodsInit::$components->components[$component]['PluginDependency']); if (!pods_is_plugin_active($dependency[1])) { $website = 'http://wordpress.org/extend/plugins/' . dirname($dependency[1]) . '/'; if (isset($dependency[2])) { $website = $dependency[2]; } if (!empty($website)) { $website = ' ' . sprintf(__('You can find it at %s', 'pods'), '<a href="' . $website . '" target="_blank">' . $website . '</a>'); } $message = sprintf(__('The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods'), PodsInit::$components->components[$component]['Name'], $dependency[0]) . $website; $ui->error($message); $ui->manage(); return; } } if (!empty(PodsInit::$components->components[$component]['ThemeDependency'])) { $dependency = explode('|', PodsInit::$components->components[$component]['ThemeDependency']); if (strtolower($dependency[1]) != strtolower(get_template()) && strtolower($dependency[1]) != strtolower(get_stylesheet())) { $website = ''; if (isset($dependency[2])) { $website = ' ' . sprintf(__('You can find it at %s', 'pods'), '<a href="' . $dependency[2] . '" target="_blank">' . $dependency[2] . '</a>'); } $message = sprintf(__('The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods'), PodsInit::$components->components[$component]['Name'], $dependency[0]) . $website; $ui->error($message); $ui->manage(); return; } } if (!empty(PodsInit::$components->components[$component]['MustUse'])) { $message = sprintf(__('The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods'), PodsInit::$components->components[$component]['Name']); $ui->error($message); $ui->manage(); return; } if (1 == pods_var('toggled')) { $toggle = PodsInit::$components->toggle($component); if (true === $toggle) { $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component enabled', 'pods')); } elseif (false === $toggle) { $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component disabled', 'pods')); } $components = PodsInit::$components->components; foreach ($components as $component => &$component_data) { $toggle = 0; if (isset(PodsInit::$components->settings['components'][$component_data['ID']])) { if (0 != PodsInit::$components->settings['components'][$component_data['ID']]) { $toggle = 1; } } if (true === $component_data['DeveloperMode']) { if (!pods_developer()) { unset($components[$component]); continue; } } $component_data = array('id' => $component_data['ID'], 'name' => $component_data['Name'], 'description' => make_clickable($component_data['Description']), 'version' => $component_data['Version'], 'author' => $component_data['Author'], 'toggle' => $toggle); } $ui->data = $components; pods_transient_clear('pods_components'); $url = pods_var_update(array('toggled' => null)); pods_redirect($url); } elseif (1 == pods_var('toggle')) { $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component enabled', 'pods')); } else { $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component disabled', 'pods')); } $ui->manage(); }