Пример #1
0
    function render($args, $instance)
    {
        global $gantry;
        $catalog = gantry_get_override_catalog($gantry->templateName);
        $override_tree = $gantry->_override_tree;
        ob_start();
        echo 'Overrides in Order Applied';
        ?>
        <ol>
            <?php 
        foreach ($override_tree as $override) {
            ?>
                <li><?php 
            echo $catalog[$override->override_id];
            ?>
 - <?php 
            echo $override->rulename;
            if (isset($override->nice_name)) {
                echo ' "' . $override->nice_name . '"';
            }
            ?>
 </li>
            <?php 
        }
        ?>
	    </ol>
		<?php 
        echo ob_get_clean();
    }
 public function init($templateName)
 {
     global $gantry_path;
     $facttypes_location = $gantry_path . '/core/rules/facttypes/';
     $this->wm->insertActionFassade('output', new GantryOverrides());
     $override_catalog = gantry_get_override_catalog($templateName);
     foreach ($override_catalog as $override_id => $override_name) {
         $assignments_option_name = $templateName . '-template-options-override-assignments-' . $override_id;
         $assignments = get_option($assignments_option_name);
         if ($assignments !== false) {
             foreach ($assignments as $archetype => $types) {
                 $facttypeclass = "GantryFact" . ucfirst($archetype);
                 if (!class_exists($facttypeclass)) {
                     $facttypepath = $facttypes_location . $archetype . ".class.php";
                     require_once $facttypepath;
                     $this->fact_paths[] = $facttypepath;
                 }
                 foreach ($types as $type => $items) {
                     if ($items === true) {
                         $this->wm->insert(new $facttypeclass($override_id, $archetype, $type));
                     }
                     if (is_array($items)) {
                         foreach ($items as $item) {
                             $this->wm->insert(new $facttypeclass($override_id, $archetype, $type, $item));
                         }
                     }
                 }
             }
         }
     }
 }
Пример #3
0
 case 'save-info':
     check_ajax_referer('save-sidebar-widgets', 'savewidgets');
     if (!current_user_can('edit_theme_options')) {
         die('-1');
     }
     unset($_POST['savewidgets'], $_POST['action'], ${$_POST}['gantry_action']);
     if (!isset($_POST['override_id']) || !isset($_POST['override_name'])) {
         return 'error';
     }
     $override_id = $_POST['override_id'];
     $override_name = $_POST['override_name'];
     if ($override_id == 0) {
         $new_override_id = count($override_catalog) > 0 ? max(array_keys($override_catalog)) + 1 : 1;
         $override_id = $new_override_id;
     }
     $override_catalog = gantry_get_override_catalog($gantry->templateName);
     $override_catalog[$override_id] = $override_name;
     gantry_udpate_override_catalog($override_catalog);
     echo "success";
     break;
 case 'widgets-order':
     check_ajax_referer('save-sidebar-widgets', 'savewidgets');
     if (!current_user_can('edit_theme_options')) {
         die('-1');
     }
     unset($_POST['savewidgets'], $_POST['action'], ${$_POST}['gantry_action']);
     if (!isset($_POST['override_id'])) {
         return "error - no override id";
     }
     $override_id = $_POST['override_id'];
     // save widgets order for all sidebars
Пример #4
0
/**
 * This function adds a set of overrides to the overrides tree.  You can pass an array of override id numbers or the names
 * ('Custom Override 1'..etc) to the function and it will set that override in line to be used in the override tree.  An
 * option priority can be passed so you can control placement in the tree.
 * @param mixed $overrides an array of override ids or names or a single override id or name
 * @param int $priority (optional)
 * @return void
 */
function gantry_set_overrides($overrides, $priority = 10)
{
    global $gantry;
    if (!is_array($overrides)) {
        $overrides = array($overrides);
    }
    $catalog = gantry_get_override_catalog($gantry->templateName);
    $overrides_to_force = array();
    foreach ($overrides as $forced_override) {
        if (is_int($forced_override) && array_key_exists($forced_override, $catalog)) {
            $overrides_to_force[] = $forced_override;
        } else {
            if ($loc = array_search($forced_override, $catalog)) {
                $overrides_to_force[] = $loc;
            } else {
                //TODO log unable to find override
            }
        }
        $gantry->addOverrides($overrides_to_force, $priority);
    }
}
Пример #5
0
 function gantry_bugfix_WGANTRYFW_5()
 {
     global $gantry;
     global $wp_registered_widget_updates;
     global $wp_registered_sidebars;
     global $_wp_sidebars_widgets;
     $widget_names = array_keys($wp_registered_widget_updates);
     foreach ($widget_names as $widget) {
         remove_filter('option_widget_' . $widget, 'gantry_setup_override_widget_instances_intercept', -1000);
     }
     $base_sidebar_widgets = $_wp_sidebars_widgets;
     foreach ($widget_names as $widget) {
         $widget_option = 'widget_' . $widget;
         $broken_instances = get_option($widget_option);
         // get widget instances without high id ones
         $base_instances = $broken_instances;
         foreach ($broken_instances as $id => $instance) {
             if (is_int($id) && $id > 10000) {
                 unset($base_instances[$id]);
             }
         }
         $remapped_base_ids = array();
         $next_id = max(array_keys($base_instances)) > 2 ? max(array_keys($base_instances)) + 1 : 3;
         $cleaned_instances = $base_instances;
         foreach ($broken_instances as $broken_id => $broken_value) {
             if (is_int($broken_id) && $broken_id > 10000) {
                 $remapped_base_ids[$broken_id] = $next_id;
                 $cleaned_instances[$next_id] = $broken_value;
                 $old_widget_name = $widget . '-' . $broken_id;
                 $new_widget_name = $widget . '-' . $next_id;
                 $found_old_widget = false;
                 foreach ($base_sidebar_widgets as $sidebar_name => &$sidebar_contents) {
                     foreach ($sidebar_contents as $sidebar_contents_id => &$sidebar_widget_instance) {
                         if ($sidebar_widget_instance == $old_widget_name) {
                             $sidebar_widget_instance = $new_widget_name;
                             $found_old_widget = true;
                             break 2;
                         }
                     }
                 }
                 if (!$found_old_widget) {
                     $base_sidebar_widgets['wp_inactive_widgets'][] = $new_widget_name;
                 }
                 $next_id++;
             }
         }
         update_option($widget_option, $cleaned_instances);
     }
     update_option('sidebars_widgets', $base_sidebar_widgets);
     $override_catalog = gantry_get_override_catalog($gantry->templateName);
     if (!empty($override_catalog)) {
         foreach ($override_catalog as $override_id => $override_widgets_option_name) {
             $override_widgets_option_name = $gantry->templateName . '-template-options-override-widgets-' . $override_id;
             $override_sidebar_name = $gantry->templateName . '-template-options-override-sidebar-' . $override_id;
             // get the widgets in the override
             $override_widget_settings = get_option($override_widgets_option_name);
             // Clean up the non override id'd widgets
             $working_overrides = $override_widget_settings;
             if ($override_widget_settings !== false) {
                 foreach ($override_widget_settings as $override_widget_type => $override_widget_instances) {
                     foreach ($override_widget_instances as $owid => $owinstance) {
                         if ($owid < $override_id * 10000 || $owid > ($override_id + 1) * 10000) {
                             unset($working_overrides[$override_widget_type][$owid]);
                         }
                     }
                 }
             }
             $remaps = array();
             // find widget_ids to renumber
             $override_sidebar = get_option($override_sidebar_name);
             foreach ($override_sidebar as $position => &$sbw_instances) {
                 foreach ($sbw_instances as $position_id => &$widget_id) {
                     $side_bar_widget_type = substr($widget_id, 0, strrpos($widget_id, '-'));
                     $widget_type_option_name = 'widget_' . $side_bar_widget_type;
                     $id_number = substr($widget_id, strrpos($widget_id, '-') + 1);
                     if ($id_number < $override_id * 10000 || $id_number > ($override_id + 1) * 10000) {
                         $keys = array_keys($working_overrides[$widget_type_option_name]);
                         if (count($keys) == 0 && empty($remaps[$widget_type_option_name])) {
                             $keys[$override_id * 10000 + 2] = $override_id * 10000 + 2;
                             $new_id = max($keys) + 1;
                         } elseif (count($keys) == 0) {
                             $remapped_ids = array_values($remaps[$widget_type_option_name]);
                             $new_id = max($remapped_ids) + 1;
                         }
                         $widget_id = $side_bar_widget_type . '-' . $new_id;
                         $remaps[$widget_type_option_name][$id_number] = $new_id;
                     }
                 }
             }
             update_option($override_sidebar_name, $override_sidebar);
             $cleaned_overrides = $override_widget_settings;
             if ($override_widget_settings !== false) {
                 foreach ($override_widget_settings as $override_widget_type => $override_widget_instances) {
                     foreach ($override_widget_instances as $owid => $owinstance) {
                         if (is_int($owid) && $owid != 2 && ($owid < $override_id * 10000 || $owid > ($override_id + 1) * 10000)) {
                             if (isset($remaps[$override_widget_type][$owid])) {
                                 $cleaned_overrides[$override_widget_type][$remaps[$override_widget_type][$owid]] = $owinstance;
                             }
                             unset($cleaned_overrides[$override_widget_type][$owid]);
                         }
                     }
                 }
             }
             update_option($override_widgets_option_name, $cleaned_overrides);
         }
     }
     update_option('gantry_bugfix_WGANTRYFW_5', true);
 }
Пример #6
0
function gantry_widgets_admin_insert_override_header()
{
    global $current_screen, $gantry, $ajaxurl;
    if ($current_screen->id == 'widgets') {
        $isDefault = !isset($_GET['override_id']);
        $override_id = 0;
        $override_catalog = gantry_get_override_catalog($gantry->templateName);
        if (isset($_GET['override_id'])) {
            $override_id = urldecode($_GET['override_id']);
            $override_name = $override_catalog[$override_id];
        }
        if ((int) $override_id == 0) {
            $next_override = count($override_catalog) > 0 ? max(array_keys($override_catalog)) + 1 : 1;
            $override_name = sprintf(_g('Custom Override %d'), $next_override);
        }
        $gantry->addStyle($gantry->gantryUrl . '/admin/widgets/gantry-widgets.css');
        $gantry->addScript($gantry->gantryUrl . '/admin/widgets/gantry-widgets.js');
        $gantry->addInlineScript("var AdminURI = '" . $ajaxurl . "';var GantryLang = {'are_you_sure': '" . _g('This will delete all widgets and settins for this override.  Are you sure you want to do this?') . "'};");
        $buffer = "";
        $buffer .= "<div id=\"gantry-overrides\">\n";
        $buffer .= "\t<div class=\"overrides-inner\">\n";
        $overridesList = array();
        if (!$isDefault) {
            $overridesList[] = '<div class="overrides-action"><a class="defaults" href="' . admin_url('widgets.php') . '">' . _g('Default Settings') . '</a></div>';
        }
        foreach ($override_catalog as $o_id => $o_name) {
            $overridesList[] = '<div class="overrides-action"><a href="' . str_replace("&", "&amp;", add_query_arg(array('override_id' => $o_id))) . '">' . $o_name . '</a></div>';
        }
        $toggleStatus = !count($overridesList) ? ' class="hidden"' : '';
        $buffer .= "\t\t<div id=\"overrides-actions\">\n\n    \t\t\t\t\t\t\t<div id=\"overrides-first\">\n\n    \t\t\t\t\t\t\t\t<a href=\"#\">" . ($isDefault ? "Default Settings" : $override_name) . "</a>\n\n    \t\t\t\t\t\t\t</div>\n\n        \t\t\t\t\t\t<div id=\"overrides-toggle\"" . $toggleStatus . "><br /></div>\n\n   \t\t\t\t\t\t\t\t<div id=\"overrides-inside\" class=\"slideUp\">\n";
        $buffer .= implode("\n", $overridesList);
        $buffer .= "\t\t\t</div>\n";
        $buffer .= "\t\t</div>\n";
        $buffer .= "\t\t<input type=\"hidden\" id=\"override_id\" value=\"" . ($isDefault ? "-1" : $override_id) . "\" />\n";
        $buffer .= "\t\t<input type=\"hidden\" id=\"override_name\" value=\"" . $override_name . "\" />\n";
        $buffer .= "\t\t<div id=\"overrides-toolbar\"" . ($isDefault ? " class=\"defaults-wrap\"" : "") . ">\n";
        if ($isDefault) {
            $buffer .= "\t\t\t<a class=\"text-button button-add\" href=\"" . admin_url('widgets.php?override_id=0') . "\"><span>New Override</span></a>\n";
        } else {
            $buffer .= "\t\t\t<a class=\"overrides-button button-add\" href=\"" . admin_url('widgets.php?override_id=0') . "\"><span>Add</span></a>\n";
            $buffer .= "\t\t\t<a class=\"overrides-button button-del\"\n               href=\"" . admin_url('admin-post.php?action=gantry_theme_delete_override&amp;from=widgets&amp;override_id=' . $override_id) . "\"><span>Delete</span></a>\n\n            \t\t\t\t\t\t<div class=\"overrides-button button-edit\"></div>\n\n\t\t\t\t\t\t\t\t\t<img width=\"16\" height=\"16\" src=\"images/wpspin_light.gif\" style=\"display: none;\" class=\"ajax-loading\">\n";
        }
        $buffer .= "\t\t</div>\n";
        $buffer .= "\t\t<div id=\"overrides-switch\">\n";
        if (!$isDefault) {
            $buffer .= '    		<a class="text-button button-widget" href="' . admin_url('admin.php?page=gantry-theme-overrides&amp;override_id=' . $override_id) . '"><span>Gantry Settings</span></a>' . "\n";
        } else {
            $buffer .= '    		<a class="text-button button-widget" href="' . admin_url('admin.php?page=gantry-theme-settings') . '"><span>Gantry Settings</span></a>' . "\n";
        }
        $buffer .= "\t\t</div>\n";
        $buffer .= "\t</div>\n";
        $buffer .= "</div>\n";
        if ($message = gantry_get_admin_message('gantry-theme-settings')) {
            $buffer .= "<div class=\"updated gantry-notice\">\n";
            $buffer .= "<p>" . $message . "</p>\n";
            $buffer .= "<div class=\"close\"><span>x</span></div>\n";
            $buffer .= "</div>";
        }
        echo $buffer;
        /*  echo "Theme config overrides HTML goes here";
                    if (isset($_GET['override_id'])) echo " Override id is " . $_GET['override_id'];
                    $gantry->addScript('iscroll.js');
            */
    }
}
Пример #7
0
 function addOverrides($overrides, $priority)
 {
     if (!array($overrides)) {
         $overrides = array($overrides);
     }
     $catalog = gantry_get_override_catalog($this->templateName);
     foreach ($overrides as $override) {
         if (array_key_exists($override, $catalog)) {
             $this->_override_tree[] = new GantryOverrideItem($override, $priority, 0, _g('Added by template function'));
         }
     }
     $this->_override_tree = GantryOverrides::sortOverridesList($this->_override_tree);
     $this->reset();
 }