public function build_edition($current_edition) { $output = ''; $editions = array(); // Since we don't have any conditions in our template, we have to build // html here. if (!isset($current_edition)) { $current_edition = EDITION_ID; } try { $edition_object = new Edition(); $editions = $edition_object->all(); } catch (Exception $error) { // It's ok if we get an error here, as this happens before we have a database setup. $editions = array(); } if ($editions && count($editions) > 1) { $output = '<select name="edition_id" id="edition_id">'; $output .= '<option value="">Search All Editions</option>'; foreach ($editions as $edition) { $output .= '<option value="' . $edition->id . '"'; if ($edition->id == $current_edition) { $output .= ' selected="selected"'; } $output .= '>' . $edition->name; if ($edition->current) { $output .= ' (current)'; } $output .= '</option>'; } $output .= '</select>'; } elseif (count($editions) == 1) { $output .= '<input type="hidden" name="edition_id" value="' . $editions[0]->id . '">'; } return $output; }
* Setup the edition object. */ require_once INCLUDE_PATH . 'class.Edition.inc.php'; global $db; $edition_obj = new Edition(array('db' => $db)); $permalink_obj = new Permalink(array('db' => $db)); /* * Create a container for our content. */ $content = new Content(); $content->set('browser_title', 'Editions'); $content->set('page_title', '<h2>Editions</h2>'); /* * Get editions. */ $editions = $edition_obj->all(); $body = '<p> These are the available editions of the code. </p>'; $body .= '<ol class="edition-list">'; foreach ($editions as $edition) { // If we have a passed url, use it. if ($_GET['from']) { $from_permalink = $permalink_obj->translate_permalink($_GET['from'], $edition->id); } // Translate our url into a shiny new permalink. $browse_permalink = $permalink_obj->translate_permalink('/browse/', $edition->id); $body .= '<li>'; if ($edition->current) { $body .= '<span class="current-edition">' . $edition->name . '</span>'; } else {
<ul>'; foreach ($law->citation as $citation) { $sidebar .= '<li>' . $citation->label . ': <span class="' . strtolower($citation->label) . '">' . $citation->text . '</span></li>'; } $sidebar .= '</ul> </section>'; } /* * End Masonry.js wrapper */ $sidebar .= '</section>'; /* * Show edition info. */ $edition_data = $edition->find_by_id($law->edition_id); $edition_list = $edition->all(); if ($edition_data && count($edition_list) > 1) { $content->set('edition', '<p class="edition">This is the <strong>' . $edition_data->name . '</strong> edition of the code. '); if ($edition_data->current) { $content->append('edition', 'This is the current edition. '); } else { $content->append('edition', 'There is <strong>not</strong> the current edition. '); } if ($edition_data->last_import) { $content->append('edition', 'It was last updated ' . date('M d, Y', strtotime($edition_data->last_import)) . '. '); } $content->append('edition', '<a href="/editions/?from=' . $_SERVER['REQUEST_URI'] . '" class="edition-link">Browse all editions.</a></p>'); } $content->set('current_edition', $law->edition_id); /* * If this isn't the canonical page, show a canonical meta tag.
function show_admin_forms($args = array()) { global $db; $edition = new Edition(array('db' => $db)); try { $editions = $edition->all(); } catch (Exception $exception) { $editions = FALSE; } if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $base_url = 'https://'; } else { $edition_url_base = 'http://'; } $edition_url_base .= $_SERVER['SERVER_NAME']; if ($_SERVER['SERVER_PORT'] != 80) { $edition_url_base .= ':' . $_SERVER['SERVER_PORT']; } $edition_url_base .= '/'; $body = '<p>What do you want to do?</p> <form method="post" action="/admin/?page=parse&noframe=1"> <h3>Import Data</h3>'; if (isset($args['import_errors'])) { $body .= '<div class="errors"> Please fix the following errors: <ul>'; foreach ($args['import_errors'] as $error) { $body .= '<li>' . $error . '</li>'; } $body .= '</div>'; } $body .= '<p>This will import all data files from your data directory: <span class="code">' . IMPORT_DATA_DIR . '</span></p> <input type="hidden" name="action" value="parse" /> <div class="option"> <input type="radio" class="radio" name="edition_option" id="edition_option_new" value="new"'; if (!$editions || $args['edition_option'] == 'existing') { $body .= 'checked="checked"'; } $body .= '/> <label for="edition_option_new">I want to create a new edition of the laws.</label> <div class="suboption"> <label for="new_edition_name">I want to call this edition</label> <div> <input type="text" class="text" name="new_edition_name" id="new_edition_name" placeholder="' . date('Y-m') . '" value="' . (isset($args['new_edition_name']) ? $args['new_edition_name'] : '') . '" /> </div> </div> <div class="suboption"> <label for="new_edition_slug">. . .</option> and the URL for this edition will be</label> <div class="edition_url">' . $edition_url_base . ' <input type="text" class="text" name="new_edition_slug" id="new_edition_slug" placeholder="' . date('Y-m') . '" value="' . (isset($args['new_edition_slug']) ? $args['new_edition_slug'] : '') . '" /> / </div> <p class="note">Note: In general, try to only use letters, numbers, and hyphens, and avoid using anything that might conflict with a section number or structure name.</p> </div> </div> <div class="option"> <input type="radio" class="radio" name="edition_option" id="edition_option_existing" value="existing"'; if (!isset($editions) || $editions === FALSE) { $body .= 'disabled="disabled"'; } elseif ($args['edition_option'] == 'existing') { $body .= 'checked="checked"'; } $body .= '/><label for="edition_option_existing">I want to update an existing edition of the laws.</label>'; if ($editions !== FALSE) { $body .= '<div class="suboption"> <p>This will remove all existing data in this edition.</p> <select name="edition" value="edition"> <option value="">Choose Edition . . .</option>'; foreach ($editions as $edition) { $body .= '<option value="' . $edition->id . '"'; if ($args['edition'] == $edition->id) { $body .= ' select="selected"'; } $body .= '>' . $edition->name; if ($edition->current === '1') { $body .= ' [current]'; } $boduy .= '</option>'; } $body .= '</select> </div>'; } else { $body .= '<div class="suboption"> You don’t have any editions yet, you’ll need to create a new one. </div>'; } $body .= '</div> <div class="option"> <input type="checkbox" class="checkbox" name="make_current" id="make_current" value="1"'; if (!$editions) { $body .= 'checked="checked"'; } $body .= ' /> <label for="make_current">Make this edition current.</label> </div> <input type="submit" value="Import" /> </form> <form method="post" action="/admin/?page=parse&noframe=1"> <h3>Empty the Database</h3> <p> Remove data from the database. This leaves database tables intact. You may choose all data, or just data from a specific edition below. </p>'; if ($editions !== FALSE) { $body .= '<div class="suboption"> <select name="edition" value="edition"> <option value="">All Data</option>'; foreach ($editions as $edition) { $body .= '<option value="' . $edition->id . '"'; if ($args['edition'] == $edition->id) { $body .= ' select="selected"'; } $body .= '>' . $edition->name; if ($edition->current === '1') { $body .= ' [current]'; } $boduy .= '</option>'; } $body .= '</select> </div>'; } $body .= '<input type="hidden" name="action" value="empty" /> <input type="submit" value="Empty the Database" /> </form> <form method="post" action="/admin/?page=parse&noframe=1"> <h3>Rebuild Permalinks</h3> <p>Completely rebuild all permalinks for all editions of code.</p> <input type="hidden" name="action" value="permalinks" /> <input type="submit" value="Rebuild Permalinks" /> </form> <form method="post" action="/admin/?page=parse&noframe=1"> <h3>Test Your Environment</h3> <p>Verifies that the State Decoded will run on the current server environment.</p> <input type="hidden" name="action" value="test_environment" /> <input type="submit" value="Test Environment" /> </form>'; /* * If Memcached / Redis is in use, provide an option to clear the cache. */ global $cache; if (isset($cache)) { $body .= ' <form method="post" action="/admin/?page=parse&noframe=1"> <h3>Clear the In-Memory Cache</h3> <p>Delete all data currently stored in Memcached or Redis.</p> <input type="hidden" name="action" value="cache" /> <input type="submit" value="Clear Cache" /> </form>'; } return $body; }