/**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     $this->theme->active_time = HabariDateTime::date_create($firstpostdate);
     // get the active theme, so we can check it
     // @todo this should be worked into the main Update::check() code for registering beacons
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // check to see if we have updates to display
     $this->theme->updates = Options::get('updates_available', array());
     // collect all the stats we display on the dashboard
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, false), 'tag_count' => Tags::vocabulary()->count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
Example #2
0
 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     if (intval($firstpostdate) !== 0) {
         $firstpostdate = time() - $firstpostdate;
     }
     $this->theme->active_time = array('years' => floor($firstpostdate / 31556736), 'months' => floor($firstpostdate % 31556736 / 2629728), 'days' => round($firstpostdate % 2629728 / 86400));
     // get the active theme, so we can check it
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // if the active plugin list has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_plugins') != Options::get('active_plugins')) {
         Cache::expire('dashboard_updates');
     }
     // if the theme version has changed, expire the updates cache
     if (Cache::has('dashboard_updates') && Cache::get('dashboard_updates_theme') != $active_theme) {
         Cache::expire('dashboard_updates');
     }
     /*
      * Check for updates to core and any hooked plugins
      * cache the output so we don't make a request every load but can still display updates
      */
     if (Cache::has('dashboard_updates')) {
         $this->theme->updates = Cache::get('dashboard_updates');
     } else {
         $updates = Update::check();
         if (!Error::is_error($updates)) {
             Cache::set('dashboard_updates', $updates);
             $this->theme->updates = $updates;
             // cache the set of plugins we just used to check for
             Cache::set('dashboard_updates_plugins', Options::get('active_plugins'));
             // cache the active theme we just used to check for
             Cache::set('dashboard_updates_theme', $active_theme);
         } else {
             $this->theme->updates = array();
         }
     }
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, FALSE), 'tag_count' => Tags::count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, FALSE) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
Example #3
0
 /**
  * Prepare and display admin page
  *
  */
 public function action_admin_theme_get_menus(AdminHandler $handler, Theme $theme)
 {
     $theme->page_content = '';
     $action = isset($_GET['action']) ? $_GET['action'] : 'create';
     switch ($action) {
         case 'edit':
             $vocabulary = Vocabulary::get_by_id(intval($handler->handler_vars['menu']));
             if ($vocabulary == false) {
                 $theme->page_content = '<h2>' . _t('Invalid Menu.');
                 // that's it, we're done. Maybe we show the list of menus instead?
                 break;
             }
             $form = new FormUI('edit_menu');
             $form->append(new FormControlText('menuname', 'null:null', _t('Name'), 'transparent_text'))->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab'))->value = $vocabulary->name;
             $form->append(new FormControlHidden('oldname', 'null:null'))->value = $vocabulary->name;
             $form->append(new FormControlText('description', 'null:null', _t('Description'), 'transparent_text'))->value = $vocabulary->description;
             $edit_items_array = $this->get_menu_type_data();
             $edit_items = '';
             foreach ($edit_items_array as $action => $menu_type) {
                 $edit_items .= '<a class="modal_popup_form menu_button_dark" href="' . URL::get('admin', array('page' => 'menu_iframe', 'action' => $action, 'menu' => $vocabulary->id)) . "\">" . _t('Add %s', array($menu_type['label'])) . "</a>";
             }
             if (!$vocabulary->is_empty()) {
                 $form->append('tree', 'tree', $vocabulary->get_tree(), _t('Menu'));
                 $form->tree->options = $vocabulary->get_tree();
                 $form->tree->config = array('itemcallback' => array($this, 'tree_item_callback'));
                 //						$form->tree->value = $vocabulary->get_root_terms();
                 // append other needed controls, if there are any.
                 $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>');
                 $form->append('submit', 'save', _t('Apply Changes'));
             } else {
                 $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>');
             }
             $delete_link = URL::get('admin', Utils::WSSE(array('page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars['menu'])));
             //$delete_link = URL::get( 'admin', array( 'page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars[ 'menu' ] ) );
             $form->append('static', 'deletebutton', '<a class="a_button" href="' . $delete_link . '">' . _t('Delete Menu') . '</a>');
             $form->append(new FormControlHidden('menu', 'null:null'))->value = $handler->handler_vars['menu'];
             $form->on_success(array($this, 'rename_menu_form_save'));
             $form->properties['onsubmit'] = "return habari.menu_admin.submit_menu_update();";
             $theme->page_content .= $form->get();
             break;
         case 'create':
             $form = new FormUI('create_menu');
             $form->append('text', 'menuname', 'null:null', _t('Menu Name'), 'transparent_text')->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab'));
             $form->append('text', 'description', 'null:null', _t('Description'), 'transparent_text');
             $form->append('submit', 'submit', _t('Create Menu'));
             $form->on_success(array($this, 'add_menu_form_save'));
             $theme->page_content = $form->get();
             break;
         case 'delete_menu':
             if (Utils::verify_wsse($_GET, true)) {
                 $menu_vocab = Vocabulary::get_by_id(intval($handler->handler_vars['menu']));
                 // Delete blocks using this menu
                 $at = Themes::get_active_data(true);
                 $t = Themes::create(Themes::get_active()['name']);
                 $i = 0;
                 foreach ($at['areas'] as $area) {
                     foreach ($t->get_blocks($area['name'], 0, $t) as $block) {
                         if ($block->type == 'menu' && $block->menu_taxonomy == $handler->handler_vars['menu']) {
                             $block->delete();
                             $i++;
                         }
                     }
                 }
                 Session::notice(sprintf(_n('%s block linking to this menu deleted.', '%s blocks linking to this menu deleted.', $i), $i));
                 $menu_vocab->delete();
                 // log that it has been deleted?
                 Session::notice(_t('Menu deleted.'));
                 // redirect to a blank menu creation form
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'create')));
             } else {
                 Session::notice(_t('Menu deletion failed - please try again.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $handler->handler_vars['menu'])));
             }
             break;
         case 'delete_term':
             $term = Term::get(intval($handler->handler_vars['term']));
             $menu_vocab = $term->vocabulary_id;
             if (Utils::verify_wsse($_GET, true)) {
                 $term->delete();
                 // log that it has been deleted?
                 Session::notice(_t('Item deleted.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab)));
             } else {
                 Session::notice(_t('Item deletion failed - please try again.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab)));
             }
             break;
         default:
             Utils::debug($_GET, $action);
             die;
     }
     $theme->display('menus_admin');
     // End everything
     exit;
 }
 /**
  * Fill the block.
  */
 public function action_block_content_creditdue($block)
 {
     $block->theme_credits = Themes::get_active();
     $block->plugin_credits = Plugins::get_active();
 }
 /**
  * Parses theme stylesheet and pulls out the colours used
  *
  * @access private
  * @return array of colors from current theme
  */
 private static function getThemeColors()
 {
     $themeFile = Themes::get_active()->theme_dir . 'style.css';
     if (is_file($themeFile)) {
         $theme_css = implode('', file($themeFile));
         preg_match_all('/:[^:,;\\{\\}].*?#([abcdef1234567890]{3,6})/i', strtoupper($theme_css), $matches);
         return array_unique($matches[1]);
     } else {
         return FALSE;
     }
 }