Example #1
0
function array_subkeys($haystack, $needle, $recursive = false)
{
    $results = array();
    foreach ($haystack as $k => $v) {
        foreach ($v as $key => $value) {
            if ($key == $needle) {
                array_push($results, $value);
            } else {
                if ($key == $recursive) {
                    array_merge($results, array_subkeys($v[$recursive], $needle, $recursive));
                }
            }
        }
    }
    return $results;
}
Example #2
0
 public static function create_display()
 {
     i18n::set('admin');
     if ($_POST['cc_form'] == 'create_page') {
         plugin('admin_create_post_pre_proccessing');
         $id = $_GET['id'];
         $title = filter('admin_create_post_title', self::get('title'));
         $content = filter('admin_create_post_content', self::get('content_area'));
         $last_modified = filter('admin_create_post_last_modified', time());
         $settings = filter('admin_create_post_settings', self::get('settings'));
         $weight = filter('admin_create_post_weight', self::get('weight'));
         $menutitle = filter('admin_create_post_menutitle', self::get('menutitle'));
         $parent_id = filter('admin_create_post_parent_id', self::get('parent_id'));
         $slug = filter('admin_create_post_slug', self::get('slug'));
         if (empty($menutitle) || empty($slug)) {
             $message = Message::error(__('blank-error'));
             plugin('admin_create_post_blank_error');
         } else {
             plugin('admin_create_post_post_proccessing');
             $values = array('title' => $title, 'content' => $content, 'settings' => unserialize($settings), 'weight' => $weight, 'menutitle' => $menutitle, 'parent_id' => $parent_id, 'slug' => $slug);
             $values = filter('admin_create_post_posted_values', $values);
             $values['settings'] = serialize($values['settings']);
             $res = Content::createNode($_GET['type'], $values);
             if ($res) {
                 $message = Message::success(sprintf(__('page-creation-successful') . ' (<a href="%s">%s</a>)', Admin::link('content'), __('view-all-pages')));
             } else {
                 $message = Message::error(__('page-creation-failed'));
             }
         }
         //Hooks::bind('post_edit_page', 'EditPage::handlePost');
     }
     $r = $message;
     $themeList = array_subkeys(Themes::getThemeList(), 'name');
     $themeList['-1'] = 'Default Theme';
     ksort($themeList);
     $form = new Form('self', 'post', 'create_page');
     $form->addHidden('settings', 'a:0:{}');
     $form->startFieldset(__('page-info'), array('id' => 'page_info_f'));
     $form->addInput(__('page-title'), 'text', 'title', self::get('title'), array('class' => 'large'));
     $form->addHidden('content_type', self::get('type'));
     $form->addSelectList(__('theme-override'), 'theme', $themeList);
     $form->addSelectList(__('parent'), 'parent_id', self::buildParentOptions(), true, $_POST['parent_id'] ? $_POST['parent_id'] : '0');
     $form->endFieldset();
     plugin('admin_create_custom_fields', array(&$form));
     $form->startFieldset(__('menu-settings'), array('id' => 'menu_settings_f'));
     $form->addInput(__('menu-title'), 'text', 'menutitle', self::get('menutitle'));
     $form->addInput(__('slug'), 'text', 'slug', self::get('slug'));
     $form->addInput(__('weight'), 'text', 'weight', $_POST['weight'] ? $_POST['weight'] : '0');
     $form->endFieldset();
     plugin('admin_create_custom_fields2', array(&$form));
     $form->startFieldset(__('content'));
     $content = self::get('content_area');
     $form->addEditor('<p></p>', 'content_area', empty($content) ? "<p></p>" : $content);
     $form->endFieldset();
     plugin('admin_create_custom_fields3', array(&$form));
     $form->addSubmit('', 'save', __('save'));
     i18n::restore();
     return array(__('admin', 'add-page'), $r . $form->endAndGetHTML());
 }
Example #3
0
 /**
  * This function returns HTML from the site's navigation.
  *
  * @param array $options The options for the nav generation. It is an associative array. Any items not named will use the default: <code>array('root' =&gt; &quot;\n&lt;ul id='ul-navigation'&gt;\n%s\n&lt;/ul&gt;\n&quot;,
  *	'child' =&gt; &quot;\n&lt;ul class='ul-sub-navigation'&gt;\n%s\n&lt;/ul&gt;\n&quot;,
  *	'item' =&gt; &quot;\n\t&lt;li&gt;&lt;a href='%2\$s' title='%1\$s'&gt;%1\$s&lt;/a&gt;&lt;/li&gt;&quot;,
  *	'itemSelected' =&gt; &quot;\n\t&lt;li class='selected'&gt;&lt;a href='%2\$s' title='%1\$s'&gt;%1\$s&lt;/a&gt;&lt;/li&gt;&quot;,
  *	'itemHasChild' =&gt; &quot;\n\t&lt;li&gt;&lt;a href='%2\$s' title='%1\$s'&gt;%1\$s&lt;/a&gt;%3\$s&lt;/li&gt;&quot;,
  *	'itemHasChildSelected' =&gt; &quot;\n\t&lt;li class='selected'&gt;&lt;a href='%2\$s' title='%1\$s'&gt;%1\$s&lt;/a&gt;%3\$s&lt;/li&gt;&quot;);</code>
  * @param bool $isChild Ignore. For internal use only.
  * @param bool $inputArray Ignore. For internal use only.
  * @return string The nav.
  */
 public static function generateNavHTML($options, $isChild = false, $inputArray = array())
 {
     if (!empty(self::$navCache) && self::$navCheck == serialize($options)) {
         return self::$navCache;
     }
     $defaults = array('root' => "\n<ul class='ul-navigation'>\n%s\n</ul>\n", 'child' => "\n<ul class='ul-sub-navigation'>\n%s\n</ul>\n", 'item' => "\n\t<li><a href='%2\$s' title='%1\$s'>%1\$s</a></li>", 'itemSelected' => "\n\t<li class='selected'><a href='%2\$s' title='%1\$s'>%1\$s</a></li>", 'itemHasChild' => "\n\t<li><a href='%2\$s' title='%1\$s'>%1\$s</a>%3\$s</li>", 'itemHasChildSelected' => "\n\t<li class='selected'><a href='%2\$s' title='%1\$s'>%1\$s</a>%3\$s</li>");
     if (!$isChild) {
         $options = array_merge($defaults, $options);
         self::$navCheck = $options;
     }
     if (empty($inputArray)) {
         $inputArray = self::parseNavigation();
     }
     foreach ($inputArray as $id => $item) {
         plugin('nav_each', $item);
         // has sub pages
         if (is_array($item['children'])) {
             $mt = UTF8::htmlentities($item['menutitle']);
             plugin('nav_haschild_before', array($item));
             $url = Node::fetchUrlForId($item['id'], $item['menutitle'], $item['slug']);
             // get the children's html
             $childrenHtml = self::generateNavHTML($options, true, $item['children']);
             $childIds = array_subkeys($item['children'], 'id', 'children');
             // current page
             if (Content::currentId() == $item['id'] || in_array(Content::currentId(), $childIds)) {
                 // add the html on
                 $thisOutput = sprintf($options['itemHasChildSelected'], $mt, $url, $childrenHtml, $item['id']);
             } else {
                 // add the html on
                 $thisOutput = sprintf($options['itemHasChild'], $mt, $url, $childrenHtml, $item['id']);
             }
             plugin('nav_haschild_after', array($item, $thisOutput, $output, $item['id']));
             $thisOutput = filter('nav_haschild_after', $thisOutput);
             $output .= $thisOutput;
         } else {
             $mt = UTF8::htmlentities($item['menutitle']);
             plugin('nav_nochild_before', array($item));
             $url = Node::fetchUrlForId($item['id'], $item['menutitle'], $item['slug']);
             // current page
             if (Content::currentId() == $item['id']) {
                 // add the html on
                 $thisOutput = sprintf($options['itemSelected'], $mt, $url, $item['id']);
             } else {
                 // add the html on
                 $thisOutput = sprintf($options['item'], $mt, $url, $item['id']);
             }
             plugin('nav_nochild_after', array($item, $thisOutput, $output));
             $thisOutput = filter('nav_nochild_after', $thisOutput);
             $output .= $thisOutput;
         }
     }
     // if it is a child block, we need some special wrapping
     if ($isChild) {
         plugin('nav_child', array($output));
         return filter('nav_child', sprintf($options['child'], $output));
     } else {
         plugin('nav_root', array($output));
         self::$navCache .= filter('nav_root', sprintf($options['root'], $output));
     }
     plugin('nav_finished', array(self::$navCache));
     self::$navCache = filter('nav_finished', self::$navCache);
     return self::$navCache;
 }