/** * Display list of the available widgets, either all or matching search. * * The search parameter are search terms separated by spaces. * * @since unknown * * @param string $show Optional, default is all. What to display, can be 'all', 'unused', or 'used'. * @param string $_search Optional. Search for widgets. Should be unsanitized. */ function wp_list_widgets() { global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls; $sort = $wp_registered_widgets; usort($sort, create_function('$a, $b', 'return strnatcasecmp( $a["name"], $b["name"] );')); $done = array(); foreach ($sort as $widget) { if (in_array($widget['callback'], $done, true)) { // We already showed this multi-widget continue; } $sidebar = is_active_widget($widget['callback'], $widget['id'], false, false); $done[] = $widget['callback']; if (!isset($widget['params'][0])) { $widget['params'][0] = array(); } $args = array('widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template'); if (isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number'])) { $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; $args['_temp_id'] = "{$id_base}-__i__"; $args['_multi_num'] = next_widget_id_number($id_base); $args['_add'] = 'multi'; } else { $args['_add'] = 'single'; if ($sidebar) { $args['_hide'] = '1'; } } $args = wp_list_widget_controls_dynamic_sidebar(array(0 => $args, 1 => $widget['params'][0])); call_user_func_array('wp_widget_control', $args); } }
function widget_get_form() { if (!wp_verify_nonce($_POST['tfb_load_nonce'], 'tfb_load_nonce')) { die(-1); } global $wp_widget_factory; require_once ABSPATH . 'wp-admin/includes/widgets.php'; $widget_class = $_POST['load_class']; if ($widget_class == '') { die(-1); } $get_instance = isset($_POST['widget_instance']) ? $_POST['widget_instance'] : ''; $instance = array(); if (is_array($get_instance) && count($get_instance) > 0) { foreach ($get_instance as $k => $s) { $instance = $s; } } $widget = new $widget_class(); $widget->number = next_widget_id_number($_POST['id_base']); ob_start(); $widget->form($instance); $form = ob_get_clean(); $widget->form = $form; echo $widget->form; echo '<br/>'; die; }
/** * Vrátí číslo (v podstatě ID) právě na základě ID property, resp. její číselné přípony * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @return int */ public function getNumber() { $id = $this->getId(); if (KT::issetAndNotEmpty($id)) { $parts = explode("-", $id); $parts = array_reverse($parts); $number = KT::tryGetInt($parts[0]); if (KT::isIdFormat($number)) { return $number; } else { return next_widget_id_number($this->getName()); } } return 0; }
/** * Build up an index of all available widgets for use in Backbone models. * * @since 3.9.0 * @access public * * @global array $wp_registered_widgets * @global array $wp_registered_widget_controls * @staticvar array $available_widgets * * @see wp_list_widgets() * * @return array List of available widgets. */ public function get_available_widgets() { static $available_widgets = array(); if (!empty($available_widgets)) { return $available_widgets; } global $wp_registered_widgets, $wp_registered_widget_controls; require_once ABSPATH . '/wp-admin/includes/widgets.php'; // for next_widget_id_number() $sort = $wp_registered_widgets; usort($sort, array($this, '_sort_name_callback')); $done = array(); foreach ($sort as $widget) { if (in_array($widget['callback'], $done, true)) { // We already showed this multi-widget continue; } $sidebar = is_active_widget($widget['callback'], $widget['id'], false, false); $done[] = $widget['callback']; if (!isset($widget['params'][0])) { $widget['params'][0] = array(); } $available_widget = $widget; unset($available_widget['callback']); // not serializable to JSON $args = array('widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template'); $is_disabled = false; $is_multi_widget = isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']); if ($is_multi_widget) { $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; $args['_temp_id'] = "{$id_base}-__i__"; $args['_multi_num'] = next_widget_id_number($id_base); $args['_add'] = 'multi'; } else { $args['_add'] = 'single'; if ($sidebar && 'wp_inactive_widgets' !== $sidebar) { $is_disabled = true; } $id_base = $widget['id']; } $list_widget_controls_args = wp_list_widget_controls_dynamic_sidebar(array(0 => $args, 1 => $widget['params'][0])); $control_tpl = $this->get_widget_control($list_widget_controls_args); // The properties here are mapped to the Backbone Widget model. $available_widget = array_merge($available_widget, array('temp_id' => isset($args['_temp_id']) ? $args['_temp_id'] : null, 'is_multi' => $is_multi_widget, 'control_tpl' => $control_tpl, 'multi_number' => $args['_add'] === 'multi' ? $args['_multi_num'] : false, 'is_disabled' => $is_disabled, 'id_base' => $id_base, 'transport' => 'refresh', 'width' => $wp_registered_widget_controls[$widget['id']]['width'], 'height' => $wp_registered_widget_controls[$widget['id']]['height'], 'is_wide' => $this->is_wide_widget($widget['id']))); $available_widgets[] = $available_widget; } return $available_widgets; }
/** * Adds a widget to WordPress. First creates a new widget instance, then * adds the widget instance to the mega menu widget sidebar area. * * @since 1.0.0 * @param string $id_base * @param int $menu_item_id * @param string $title */ public function _add_widget($id_base, $menu_item_id, $title, $total_cols) { require_once ABSPATH . 'wp-admin/includes/widgets.php'; $next_id = next_widget_id_number($id_base); $this->add_widget_instance($id_base, $next_id, $menu_item_id); $widget_id = $this->add_widget_to_sidebar($id_base, $next_id); $return = $this->get_widget_html($title, $widget_id, 4, $total_cols); return array('content' => $return, 'id' => $widget_id); }
/** * Adds a widget to WordPress. First creates a new widget instance, then * adds the widget instance to the mega menu widget sidebar area. * * @since 1.0 * @param string $id_base * @param int $menu_item_id * @param string $title */ public function add_widget($id_base, $menu_item_id, $title) { require_once ABSPATH . 'wp-admin/includes/widgets.php'; $next_id = next_widget_id_number($id_base); $this->add_widget_instance($id_base, $next_id, $menu_item_id); $widget_id = $this->add_widget_to_sidebar($id_base, $next_id); $return = '<div class="widget" data-columns="2" id="' . $widget_id . '" data-widget-id="' . $widget_id . '">'; $return .= ' <div class="widget-top">'; $return .= ' <div class="widget-title-action">'; $return .= ' <a class="widget-option widget-contract"></a>'; $return .= ' <a class="widget-option widget-expand"></a>'; $return .= ' <a class="widget-option widget-action"></a>'; $return .= ' </div>'; $return .= ' <div class="widget-title">'; $return .= ' <h4>' . $title . '</h4>'; $return .= ' </div>'; $return .= ' </div>'; $return .= ' <div class="widget-inner"></div>'; $return .= '</div>'; return $return; }
/** * Generates the widget form * * @since 1.0 * @return string */ function get_widget_form($widget, $name, $options = array()) { global $wp_widget_factory; require_once ABSPATH . 'wp-admin/includes/widgets.php'; if (!is_array($options)) { $options = array(); } $options = array_merge($options, array('number' => next_widget_id_number(0))); ob_start(); $wp_widget_factory->widgets[$widget]->form($options); do_action_ref_array('in_widget_form', array($wp_widget_factory->widgets[$widget], null, $options)); $form = ob_get_clean(); $base_name = 'widget-' . $wp_widget_factory->widgets[$widget]->id_base . '\\[' . $wp_widget_factory->widgets[$widget]->number . '\\]'; $form = preg_replace("/{$base_name}/", $name, $form); return $form; }
function importTheme() { WP_Filesystem(); $messedids = array(); global $wpdb; if (is_multisite()) { global $blog_id; $prel = $blog_id . '_'; } else { $prel = ''; } move_uploaded_file($_FILES["importer"]["tmp_name"], THEME_CACHE_DIR . "/" . $_FILES["importer"]["name"]); $nfile = THEME_CACHE_DIR . "/" . $_FILES["importer"]["name"]; $unzipit = unzip_file($nfile, THEME_CACHE_DIR . '/' . str_replace('.zip', '', $_FILES["importer"]["name"])); $file = THEME_CACHE_DIR . "/" . str_replace('.zip', '', $_FILES["importer"]["name"]) . '/export.utx'; $raw_content = file_get_contents($file); $content = base64_decode($raw_content); $theme = unserialize($content); /*echo '<pre>'; print_r($theme); echo "</pre>"; die();*/ // Do Images if (is_array($theme['images'])) { $images = $theme['images']; foreach ($images as $image) { $imagespath = THEME_CACHE_DIR . '/' . $prel . $theme['name']; $imagesurlpath = THEME_CACHE_URI . '/' . $prel . $theme['name']; $imagefilename = basename($image['name']); $imagefile = $imagespath . '/' . $imagefilename; if (is_file($imagefile)) { $newimage = $imagesurlpath . '/' . $imagefilename; $theme = replaceTree($image['name'], $newimage, $theme); } } // Images Done } // Create the Theme $table = $wpdb->prefix . 'ultimatum_themes'; $ltable = $wpdb->prefix . 'ultimatum_layout'; $atable = $wpdb->prefix . 'ultimatum_layout_assign'; $rtable = $wpdb->prefix . 'ultimatum_rows'; $ctable = $wpdb->prefix . 'ultimatum_css'; $classtable = $wpdb->prefix . 'ultimatum_classes'; $themesql = "INSERT INTO {$table} (`name`, `details`,`browsers`,`width`,`margin`,`type`,`published`,`template`) VALUES ('{$theme['name']}','{$theme['details']}','','{$theme['width']}','{$theme['margin']}','{$theme['type']}','{$theme['published']}','" . THEME_CODE . "')"; $wpdb->query($themesql); $themeid = $wpdb->insert_id; foreach ($theme['layouts'] as $layout) { if ($layout['type'] == 'part') { $layoutsql = "INSERT INTO {$ltable} (`title`,`type`,`theme`,`default`) VALUES ('{$layout['name']}','{$layout['type']}','{$themeid}','{$layout['default']}')"; $wpdb->query($layoutsql); $layoutid = $wpdb->insert_id; $old_lay_id = $layout['oldid']; $partconv[$old_lay_id] = $layoutid; } else { $new_parts_before = array(); $lbefore = ''; if ($layout['before']) { $old_parts_before = explode(',', $layout['before']); foreach ($old_parts_before as $p_b) { $new_parts_before[] = $partconv[$p_b]; } $lbefore = implode(',', $new_parts_before); } $new_parts_after = array(); $lafter = ''; if ($layout['after']) { $old_parts_after = explode(',', $layout['after']); foreach ($old_parts_after as $p_b) { $new_parts_after[] = $partconv[$p_b]; } $lafter = implode(',', $new_parts_after); } $layoutsql = "INSERT INTO {$ltable} (`title`,`type`,`theme`,`default`,`before`,`after`) VALUES ('{$layout['name']}','{$layout['type']}','{$themeid}','{$layout['default']}','{$lbefore}','{$lafter}')"; $wpdb->query($layoutsql); $layoutid = $wpdb->insert_id; if ($_POST['assigners'] == 'assign') { if (count($layout['assigned']) != 0) { foreach ($layout['assigned'] as $assignemnt) { $query = "REPLACE INTO {$atable} VALUES ('" . THEME_CODE . "','{$assignemnt}','{$layoutid}')"; $wpdb->query($query); } } } } // Insert Layout CSS in WP Options and Generate file if ($layout['type'] == 'full') { $optionname = THEME_CODE . '_' . $layoutid . '_css'; update_option($optionname, $layout['css']); createCSS($layoutid, $prel, $layout['css']); // Create Custom CSS file if (strlen($layout['custom_css']) > 0) { $file = THEME_CACHE_DIR . '/custom_' . $prel . $layoutid . '.css'; if (file_exists($file)) { unlink($file); } $fhandle = @fopen($file, 'w+'); if ($fhandle) { fwrite($fhandle, $layout['custom_css'], strlen($layout['custom_css'])); } } } // Do the ROWS $rows = $layout['rows']; foreach ($rows as $row) { // Insert the row and get id $rowsql = "INSERT INTO {$rtable} (`layout_id`, `type_id`) VALUES ('{$layoutid}','{$row['type']}')"; $wpdb->query($rowsql); $rowid = $wpdb->insert_id; $layoutrows[] = $rowid; // Insert row wrapper CSS $wrapper = 'wrapper-' . $rowid; foreach ($row['wrapper'] as $element => $property) { if ($element != 'custom_classes') { $properties = serialize($property); $wrappersql = "INSERT INTO {$ctable} VALUES ('','{$wrapper}','{$layoutid}','{$element}','{$properties}')"; $wpdb->query($wrappersql); } else { $properties = unserialize($property); if (count($properties) != 0) { $classql = "REPLACE INTO {$classtable} (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('{$wrapper}','" . $properties["user_class"] . "','" . $properties["hidephone"] . "','" . $properties["hidetablet"] . "','" . $properties["hidedesktop"] . "','" . $properties["layout_id"] . "')"; $wpdb->query($classql); } } } // Insert row container CSS $container = 'container-' . $rowid; foreach ($row['container'] as $element => $property) { if ($element != 'custom_classes') { $properties = serialize($property); $containersql = "INSERT INTO {$ctable} VALUES ('','{$container}','{$layoutid}','{$element}','{$properties}')"; $wpdb->query($containersql); } else { $properties = unserialize($property); if (count($properties) != 0) { $classql = "REPLACE INTO {$classtable} (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('{$container}','" . $properties["user_class"] . "','" . $properties["hidephone"] . "','" . $properties["hidetablet"] . "','" . $properties["hidedesktop"] . "','" . $properties["layout_id"] . "')"; $wpdb->query($classql); } } } // Insert row Column CSS foreach ($row['col'] as $colid => $colcss) { $column = 'col-' . $layoutid . '-' . $colid; foreach ($colcss as $element => $property) { if ($element != 'custom_classes') { $properties = serialize($property); $colsql = "INSERT INTO {$ctable} VALUES ('','{$column}','{$layoutid}','{$element}','{$properties}')"; $wpdb->query($colsql); } else { $properties = unserialize($property); if (count($properties) != 0) { $classql = "REPLACE INTO {$classtable} (`container`,`user_class`,`hidephone`,`hidetablet`,`hidedesktop`,`layout_id`) VALUES ('{$column}','" . $properties["user_class"] . "','" . $properties["hidephone"] . "','" . $properties["hidetablet"] . "','" . $property["hidedesktop"] . "','" . $properties["layout_id"] . "')"; $wpdb->query($classql); } } } } //Import the widgets foreach ($row["widgets"] as $sidebar => $widgets) { foreach ($widgets as $widget) { $option = $widget['widget_name']; $id_base = $widget['id_base']; if (isset($messedids[$option])) { $nextid = $messedids[$option] + 1; $messedids[$option] = $nextid; } else { $nextid = next_widget_id_number($widget['id_base']); $messedids[$option] = $nextid; } $warray = get_option($option); unset($widget['widget_name']); unset($widget['id_base']); $warray[$nextid] = $widget; update_option($option, $warray); $ultimatum_sidebars_widgets = get_option('ultimatum_sidebars_widgets'); $ultimatum_sidebars_widgets['sidebar-' . $rowid . '-' . $sidebar][] = $id_base . '-' . $nextid; update_option('ultimatum_sidebars_widgets', $ultimatum_sidebars_widgets); unset($warray); } } // Widget import Done :) } // GENERATE Layout specific CSS // Save the CSS $file = THEME_CACHE_DIR . '/layout_' . $prel . $layoutid . '.css'; $query = "SELECT * FROM {$ctable} WHERE layout_id='{$layoutid}'"; $res = $wpdb->get_results($query, ARRAY_A); $css = ''; foreach ($res as $fetch) { if ($fetch["element"] == 'general') { if ($fetch["container"] != 'body') { if (eregi('col-', $fetch["container"])) { $el = '#' . $fetch["container"] . ' .colwrapper'; } else { $el = '#' . $fetch["container"]; } } else { $el = $fetch["container"]; } } elseif ($fetch["container"] == 'body') { if ($fetch["element"] == 'h1' || $fetch["element"] == 'h2' || $fetch["element"] == 'h3' || $fetch["element"] == 'h4' || $fetch["element"] == 'h5' || $fetch["element"] == 'h6') { $fetch["element"] = $fetch["element"] . ', ' . $fetch["element"] . ' a,' . $fetch["element"] . ' a:hover'; } $el = $fetch["element"]; if ($el == 'ahover') { $el = 'a:hover'; } } else { if ($fetch["element"] == 'ahover') { $fetch["element"] = 'a:hover'; } if ($fetch["element"] == 'h1' || $fetch["element"] == 'h2' || $fetch["element"] == 'h3' || $fetch["element"] == 'h4' || $fetch["element"] == 'h5' || $fetch["element"] == 'h6') { //$fetch[element]=$fetch[element].', '.$fetch[element].' a,'.$fetch[element].' a:hover'; $el = '#' . $fetch["container"] . ' ' . $fetch["element"] . ', #' . $fetch["container"] . ' ' . $fetch["element"] . ' a, #' . $fetch["container"] . ' ' . $fetch["element"] . ' a:hover'; } else { $el = '#' . $fetch["container"] . ' ' . $fetch["element"]; } } $proprties = parseCSS($fetch["properties"]); if (count($proprties) != 0) { $css .= $el . '{' . @implode(';', $proprties) . '}'; } } if (strlen($css) != 0) { $fhandle = @fopen($file, 'w+'); if ($fhandle) { fwrite($fhandle, $css, strlen($css)); } } $rowss = implode(',', $layoutrows); unset($layoutrows); $layoutupdatesql = "UPDATE {$ltable} SET `rows`='{$rowss}' WHERE `id`='{$layoutid}'"; $wpdb->query($layoutupdatesql); } // layouts foreach finish $file = THEME_CACHE_DIR . "/" . $_FILES["importer"]["name"]; unlink($file); echo 'Import Successfull'; $url = curPageURL(); }
/** * Adds a widget to WordPress. First creates a new widget instance, then * adds the widget instance to the mega menu widget sidebar area. * * @since 1.0 * @param string $id_base * @param int $menu_item_id */ public function add_widget($id_base, $menu_item_id) { require_once ABSPATH . 'wp-admin/includes/widgets.php'; $next_id = next_widget_id_number($id_base); $this->add_widget_instance($id_base, $next_id, $menu_item_id); $widget_id = $this->add_widget_to_sidebar($id_base, $next_id); return $widget_id; }
/** * Adds a widget to WordPress. First creates a new widget instance, then * adds the widget instance to the mega menu widget sidebar area. * * @since 1.0 * @param string $id_base * @param int $menu_item_id * @param string $title */ public function add_widget($id_base, $menu_item_id, $title) { require_once ABSPATH . 'wp-admin/includes/widgets.php'; $next_id = next_widget_id_number($id_base); $this->add_widget_instance($id_base, $next_id, $menu_item_id); $widget_id = $this->add_widget_to_sidebar($id_base, $next_id); $return = '<div class="widget" title="' . esc_attr($title) . '" data-columns="2" id="' . $widget_id . '" data-type="widget" data-id="' . $widget_id . '">'; $return .= ' <div class="widget-top">'; $return .= ' <div class="widget-title-action">'; $return .= ' <a class="widget-option widget-contract" title="' . esc_attr(__("Contract", "megamenu")) . '"></a>'; $return .= ' <span class="widget-cols"><span class="widget-num-cols">2</span><span class="widget-of">/</span><span class="widget-total-cols">X</span></span>'; $return .= ' <a class="widget-option widget-expand" title="' . esc_attr(__("Expand", "megamenu")) . '"></a>'; $return .= ' <a class="widget-option widget-action" title="' . esc_attr(__("Edit", "megamenu")) . '"></a>'; $return .= ' </div>'; $return .= ' <div class="widget-title">'; $return .= ' <h4>' . esc_html($title) . '</h4>'; $return .= ' </div>'; $return .= ' </div>'; $return .= ' <div class="widget-inner"></div>'; $return .= '</div>'; return $return; }
/** * Install default content when theme is activated. * * Set the 'PC_INSTALL_DEFAULT_CONTENT' and 'PC_INSTALL_CONTENT_PROMPT' constants * to control how this appears to the user. * * @since 0.1.0 */ public static function install_default_content($theme_options_url) { /* Create default content, and configure menus, widgets etc. */ /* Add some default pages. */ $pages = array(array('title' => 'Blog', 'content' => '', 'template' => 'blog-page.php'), array('title' => 'About Us', 'content' => 'Some information all about us.', 'template' => ''), array('title' => 'Sitemap', 'content' => '', 'template' => 'sitemap-page.php'), array('title' => 'Contact Us', 'content' => 'Please use the contact form below for all enquiries. We will respond to your message as soon as possible.', 'template' => 'contact-page.php')); /* Create some new theme pages. */ self::create_theme_pages($pages); /* Create nav menu if it doesn't already exist and add some pages. */ self::create_new_theme_nav_menu($pages); /* Define the multi number for each widget type here, then increment for each additional widget added of the same type. */ global $pc_info_box_multi_number; $pc_info_box_multi_number = next_widget_id_number('pc_info_widget_' . PC_THEME_NAME_SLUG); /* Add an Info Box widget to the header widget area. */ $info_box_widget = array('widget_area' => 'header-widget-area', 'widget_name' => 'Info Box', 'default_settings' => array('title' => 'Header Info Box', 'info_description' => '', 'phone_number' => '(949) 867-5307', 'facebook_id' => 'PressCoders', 'twitter_id' => 'presscoders', 'youtube_id' => 'PressCoders', 'flickr_id' => '', 'googleplus_id' => 'http://plus.google.com', 'linkedin_id' => 'http://www.linkedin.com', 'rss_id' => 'http://www.presscoders.com', 'custom_id_1' => '', 'custom_img_1' => '', 'show_search' => '')); self::add_default_widget($info_box_widget, true); /* Install extra content if demo site active. */ if (PC_INSTALL_DEMO_CONTENT && method_exists('PC_TS_Utility', 'theme_demo_default_content')) { /* Install theme specific demo content if class method has been declared. */ PC_TS_Utility::theme_demo_default_content(); } /* Render theme activation message. */ self::theme_activation_message($theme_options_url); }