private function save_user_page($user) { $path = NeechyPath::join($this->html_path(), 'new-page.md.php'); $page = Page::find_by_title($user->field('name')); $page->set('body', $this->t->render_partial_by_path($path)); $page->set('editor', 'NeechySystem'); $page->save(); return $page; }
/** * Tests */ public function testUrl() { $cases = array(array(array('MyPage', NULL, NULL), '?page=MyPage'), array(array('MyPage', 'handler', NULL), '?page=MyPage&handler=handler'), array(array('MyPage', NULL, 'action'), '?page=MyPage&action=action'), array(array('MyPage', 'handler', 'action'), '?page=MyPage&handler=handler&action=action')); foreach ($cases as $case) { list($args, $expected) = $case; list($page, $handler, $action) = $args; $url = NeechyPath::url($page, $handler, $action); $this->assertEquals($expected, $url); } }
private function load_handler() { $handler_app_path = NeechyPath::join(NEECHY_HANDLER_APP_PATH, $this->request->handler, 'handler.php'); $handler_core_path = NeechyPath::join(NEECHY_HANDLER_CORE_PATH, $this->request->handler, 'handler.php'); $HandlerClass = sprintf('%sHandler', ucwords($this->request->handler)); if (file_exists($handler_app_path)) { require_once $handler_app_path; } elseif (file_exists($handler_core_path)) { require_once $handler_core_path; } else { throw new NeechyWebServiceError(sprintf('handler %s not found', $this->request->handler), 404); } $handler = new $HandlerClass($this->request); return $handler; }
public static function create_on_install() { $pages_created = array(); $pages_dir = NeechyPath::join(NEECHY_APP_PATH, 'templates/core_pages'); $templater = NeechyTemplater::load(); foreach (self::$core_pages as $name) { $basename = sprintf('%s.md.php', $name); $path = NeechyPath::join($pages_dir, $basename); $page_body = $templater->render_partial_by_path($path); $page = Page::find_by_title($name); $page->set('body', $page_body); $page->set('editor', NEECHY_USER); $page->save(); $pages_created[] = $page; } return $pages_created; }
public function handle() { # Flash warning if user tries to save changes if ($this->request->action_is('save')) { $this->t->flash('Cannot update README.md file', 'warning'); } # Set content $path = NeechyPath::root('README.md'); $readme_body = file_get_contents($path); $this->t->data('editor', $this->t->render_editor($readme_body)); # Partial variables $last_edited = ''; $page_title = 'README.md'; # Render partial $view_path = NeechyPath::root('core/handlers/page/html/content.html.php'); $this->t->data('page-title', $page_title); $this->t->data('last-edited', $last_edited); $content = $this->render_view($view_path); return $content; }
public function build_page_tab_menu($page_title) { $page_tabs = array('page' => $page_title, 'editor' => 'Edit', 'history' => 'History'); $tabs_by_user_status = array('default' => array('page', 'history'), 'logged-in' => array_keys($page_tabs)); $user_status = AppUser::is_logged_in() ? 'logged-in' : 'default'; $user_tabs = $tabs_by_user_status[$user_status]; $tab_links = array(); foreach ($user_tabs as $handler) { $label = $page_tabs[$handler]; $href = NeechyPath::url($this->request->page, $handler); $classes = array($handler); if ($handler == 'page') { $classes[] = 'title'; } if ($handler == $this->request->handler) { $classes[] = 'active'; } if ($this->request->handler == 'editor' && $handler == $this->request->handler && $this->request->action == 'preview') { $label = 'Preview'; } $tab_links[] = $this->build_page_tab_link($label, $href, $classes); } return implode("\n", $tab_links); }
private function load_layout() { # First look in theme directory $layout_path = NeechyPath::join($this->theme_path, self::THEME_LAYOUT_PATH); if (file_exists($layout_path)) { return $this->buffer($layout_path); } # If not found there, default to core layout $layout_path = NeechyPath::join(NEECHY_ROOT, self::CORE_LAYOUT_PATH); return $this->buffer($layout_path); }
# # Version # define('NEECHY_VERSION', '0.1'); define('NEECHY_URL', 'https://github.com/klenwell/neechy'); # # Path Constants # define('NEECHY_ROOT', dirname(dirname(dirname(__FILE__)))); define('NEECHY_APP_PATH', NeechyPath::join(NEECHY_ROOT, 'app')); define('NEECHY_CONFIG_PATH', NeechyPath::join(NEECHY_ROOT, 'config')); define('NEECHY_CORE_PATH', NeechyPath::join(NEECHY_ROOT, 'core')); define('NEECHY_PUBLIC_PATH', NeechyPath::join(NEECHY_ROOT, 'public')); define('NEECHY_CONSOLE_PATH', NeechyPath::join(NEECHY_ROOT, 'console')); define('NEECHY_HANDLER_CORE_PATH', NeechyPath::join(NEECHY_CORE_PATH, 'handlers')); define('NEECHY_HANDLER_APP_PATH', NeechyPath::join(NEECHY_APP_PATH, 'handlers')); define('NEECHY_TASK_CONSOLE_PATH', NeechyPath::join(NEECHY_CONSOLE_PATH, 'tasks')); define('NEECHY_TASK_APP_PATH', NeechyPath::join(NEECHY_APP_PATH, 'tasks')); # # MySQL / Database Constants # define('MYSQL_ENGINE', 'MyISAM'); # # Regular Expression Patterns # define('RE_BRACKET_TOKENS', '/\\{\\{\\s*[^\\}]+\\}\\}/'); define('RE_EXTRACT_BRACKET_TOKEN_ID', '/[\\{\\}\\s]/'); # # Miscellaneous # define('NEECHY_USER', 'NeechySystem');
<?php # # Neechy Signup/Login Form # Source: http://getbootstrap.com/examples/signin/ # $t = $this; # templater object $t->append_to_head($t->css_link($t->css_href('form.css'))); # General vars $alert = $t->data('alert'); $post_url = NeechyPath::url('login', 'auth'); $validation_errors = $t->data('validation-errors'); # # Helper function # function auth_field($field, $attrs, $t) { $type = $attrs[0]; $placeholder = $attrs[1]; $autofocus = isset($attrs[2]) ? $attrs[2] : false; $value = $type == 'password' ? NULL : $t->data($field); $options = array('class' => 'form-control', 'placeholder' => $placeholder, 'required' => NULL); if ($autofocus) { $options['autofocus'] = NULL; } $html = $t->input_field($type, $field, $value, $options); # Apply error styling if appropriate if (isset($validation_errors[$field])) { $html = apply_field_state('error', $html); }
<?php $t = $this; # templater object $page_url = NeechyPath::url($t->request->page, 'page'); ?> <table class="table table-condensed"> <tr> <th>id</th> <th>editor</th> <th>size</th> <th>datetime</th> </tr> <?php foreach ($t->data('edits') as $row) { ?> <tr> <td class="id"><?php echo $row['id']; ?> </td> <td class="editor"><?php echo $row['editor']; ?> </td> <td class="body"><?php echo strlen($row['body']); ?> </td> <td class="created_at"><?php echo $row['created_at'];
protected function register_admin_user($name, $email, $password) { $level = 'ADMIN'; # Create user and default page $user = User::register($name, $email, $password, $level); # Create default page $path = NeechyPath::join($this->html_path(), 'owner-page.md.php'); $page = Page::find_by_title($user->field('name')); $page->set('body', $this->read_page_body_from_template($path)); $page->set('editor', 'NeechySystem'); $page->save(); return $page; }
public function neechy_link($label, $handler = null, $page = null, $action = null, $attrs = array()) { $page = is_null($page) ? $label : $page; $href = NeechyPath::url($page, $handler, $action); return $this->link($href, $label, $attrs); }
<?php # # Neechy Password View # require_once '../core/handlers/password/php/helper.php'; $t = $this; # templater object $t->append_to_head($t->css_link($t->css_href('form.css'))); $validator = $t->data('form-validator'); $helper = new PasswordHelper(); # General vars $post_url = NeechyPath::url('change', 'password'); ?> <div class="password handler"> <h2>Password</h2> <div id="neechy-pass" class="row"> <div id="neechy-login" class="well-sm col-xs-offset-1 col-xs-5"> <?php echo $helper->open_form($post_url); ?> <h3>Change Password</h2> <?php echo $helper->password_group('old-password', 'Old Password', true, $validator); ?> <?php echo $helper->password_group('new-password', 'New Password (8 chars min)', false, $validator); ?> <?php echo $helper->password_group('new-password-confirm', 'New Password (confirm)', false, $validator);
private function handler_path() { $handler_name = $this->action; $handler_app_path = NeechyPath::join(NEECHY_HANDLER_APP_PATH, $handler_name, 'handler.php'); $handler_core_path = NeechyPath::join(NEECHY_HANDLER_CORE_PATH, $handler_name, 'handler.php'); if (file_exists($handler_app_path)) { return $handler_app_path; } elseif (file_exists($handler_core_path)) { return $handler_core_path; } else { return NULL; } }
public static function root($sub_path = '') { $root = NeechyPath::abspath(NeechyPath::join(__DIR__, '../..')); return NeechyPath::join($root, $sub_path); }
public function url($handler = NULL, $action = NULL, $params = array()) { return NeechyPath::url($this->field('name'), $handler, $action, $params); }
private function assert_core_config_present() { $core_config_path = NeechyPath::join(NEECHY_ROOT, self::CORE_PATH); if (!file_exists($core_config_path)) { throw new NeechyConfigError(sprintf('Core config file [%s] missing', $core_config_path)); } return $core_config_path; }
protected function html_path() { return NeechyPath::join(NEECHY_HANDLER_CORE_PATH, $this->folder_name(), 'html'); }