<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[GlotPress][710] trunk: Add per-profile settings.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://glotpress.trac.wordpress.org/changeset/710">710</a></dd>
<dt>Author</dt> <dd>nbachiyski</dd>
<dt>Date</dt> <dd>2012-10-30 23:24:47 +0000 (Tue, 30 Oct 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add per-profile settings.
Adds /profile where you can set number of items per page, default sort
by, and default sort order.
Props joostdevalk, fixes <a href="http://glotpress.trac.wordpress.org/ticket/14">#14</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkcssstylecss">trunk/css/style.css</a></li>
<li><a href="#trunkgpincludesmetaphp">trunk/gp-includes/meta.php</a></li>
<li><a href="#trunkgpincludesrouterphp">trunk/gp-includes/router.php</a></li>
<li><a href="#trunkgpincludesroutestranslationphp">trunk/gp-includes/routes/translation.php</a></li>
<li><a href="#trunkgpincludesthingphp">trunk/gp-includes/thing.php</a></li>
<li><a href="#trunkgpincludesthingstranslationphp">trunk/gp-includes/things/translation.php</a></li>
<li><a href="#trunkgpincludesthingsuserphp">trunk/gp-includes/things/user.php</a></li>
<li><a href="#trunkgptemplatesheaderphp">trunk/gp-templates/header.php</a></li>
<li><a href="#trunkgptemplatestranslationsphp">trunk/gp-templates/translations.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkcssstylecss"></a>
<div class="modfile"><h4>Modified: trunk/css/style.css (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/css/style.css        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/css/style.css        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -588,4 +588,11 @@
</span><span class="cx"> }
</span><span class="cx"> span.or-cancel {
</span><span class="cx">         font-size: 0.85em;
</span><ins>+}
+table.form-table th {
+        text-align: left;
+        vertical-align: text-top;
+}
+table.form-table th, table.form-table td {
+        padding: 10px 0 0 0;
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkgpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/meta.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/meta.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/meta.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -17,6 +17,7 @@
</span><span class="cx"> */
</span><span class="cx"> function gp_update_meta( $object_id = 0, $meta_key, $meta_value, $type, $global = false ) {
</span><span class="cx">         global $gpdb;
</span><ins>+
</ins><span class="cx">         if ( !is_numeric( $object_id ) || empty( $object_id ) && !$global ) {
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="lines">@@ -369,4 +370,4 @@
</span><span class="cx">
</span><span class="cx"> function gp_delete_option( $option, $value = '' ) {
</span><span class="cx">         return gp_delete_meta( 0, $option, $value, 'option', true );
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins></span></pre></div>
<a id="trunkgpincludesrouterphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/router.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/router.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/router.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -44,6 +44,9 @@
</span><span class="cx">                         'get:/login' => array('GP_Route_Login', 'login_get'),
</span><span class="cx">                         'post:/login' => array('GP_Route_Login', 'login_post'),
</span><span class="cx">                         'get:/logout' => array('GP_Route_Login', 'logout'),
</span><ins>+                        
+                        'get:/profile' => array('GP_Route_Profile', 'profile_get'),
+                        'post:/profile' => array('GP_Route_Profile', 'profile_post'),
</ins><span class="cx">
</span><span class="cx">                         "get:/$project/import-originals" => array('GP_Route_Project', 'import_originals_get'),
</span><span class="cx">                         "post:/$project/import-originals" => array('GP_Route_Project', 'import_originals_post'),
</span></span></pre></div>
<a id="trunkgpincludesroutestranslationphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/routes/translation.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/routes/translation.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/routes/translation.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -67,9 +67,16 @@
</span><span class="cx">                 if ( 'random' == gp_array_get( $sort, 'by') ) {
</span><span class="cx">                         add_filter( 'gp_pagination', create_function( '$html', 'return "";' ) );
</span><span class="cx">                 }
</span><ins>+
+                $per_page = GP::$user->current()->get_meta('per_page');
+                if ( 0 == $per_page )
+                        $per_page = GP::$translation->per_page;
+                else
+                        GP::$translation->per_page = $per_page;
+
</ins><span class="cx">                 $translations = GP::$translation->for_translation( $project, $translation_set, $page, $filters, $sort );
</span><span class="cx">                 $total_translations_count = GP::$translation->found_rows;
</span><del>-                $per_page = GP::$translation->per_page;
</del><ins>+                
</ins><span class="cx">                 $can_edit = GP::$user->logged_in();
</span><span class="cx">                 $can_write = $this->can( 'write', 'project', $project->id );
</span><span class="cx">                 $can_approve = $this->can( 'approve', 'translation-set', $translation_set->id );
</span></span></pre></div>
<a id="trunkgpincludesthingphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/thing.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/thing.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/thing.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -384,7 +384,7 @@
</span><span class="cx">                 $per_page = is_null( $per_page )? $this->per_page : $per_page;
</span><span class="cx">                 if ( 'no-limit' == $per_page || 'no-limit' == $page ) return '';
</span><span class="cx">                 $page = intval( $page )? intval( $page ) : 1;
</span><del>-                return sprintf( "LIMIT %d OFFSET %d", $this->per_page, ($page-1)*$this->per_page );
</del><ins>+                return sprintf( "LIMIT %d OFFSET %d", $per_page, ($page-1)*$per_page );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function found_rows() {
</span></span></pre></div>
<a id="trunkgpincludesthingstranslationphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/things/translation.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/things/translation.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/things/translation.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -72,9 +72,18 @@
</span><span class="cx">                 $sort_bys = array('original' => 'o.singular %s', 'translation' => 't.translation_0 %s', 'priority' => 'o.priority %s, o.date_added DESC',
</span><span class="cx">                         'random' => 'o.priority DESC, RAND()', 'translation_date_added' => 't.date_added %s', 'original_date_added' => 'o.date_added %s',
</span><span class="cx">                         'references' => 'o.references' );
</span><del>-                $sort_by = gp_array_get( $sort_bys, gp_array_get( $sort, 'by' ), 'o.priority %1$s, o.date_added %1$s' );
</del><ins>+
+                $default_sort = GP::$user->current()->get_meta('default_sort');
+                if ( ! is_array($default_sort) ) {
+                        $default_sort = array(
+                                'by' => 'priority',
+                                'how' => 'desc'
+                        );
+                }
+                
+                $sort_by = gp_array_get( $sort_bys, gp_array_get( $sort, 'by' ), gp_array_get( $sort_bys, $default_sort['by'] ) );
</ins><span class="cx">                 $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC', );
</span><del>-                $sort_how = gp_array_get( $sort_hows, gp_array_get( $sort, 'how' ), 'DESC' );
</del><ins>+                $sort_how = gp_array_get( $sort_hows, gp_array_get( $sort, 'how' ), gp_array_get( $sort_hows, $default_sort['how'] ) );
</ins><span class="cx">
</span><span class="cx">                 $where = array();
</span><span class="cx">                 if ( gp_array_get( $filters, 'term' ) ) {
</span><span class="lines">@@ -138,14 +147,16 @@
</span><span class="cx">                 if ( $where ) {
</span><span class="cx">                         $where = 'AND '.$where;
</span><span class="cx">                 }
</span><del>-
</del><ins>+                
</ins><span class="cx">                 $join_where = implode( ' AND ', $join_where );
</span><span class="cx">                 if ( $join_where ) {
</span><span class="cx">                         $join_where = 'AND '.$join_where;
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 $sql_sort = sprintf( $sort_by, $sort_how );
</span><del>-                $limit = $this->sql_limit_for_paging( $page );
</del><ins>+
+                $limit = $this->sql_limit_for_paging( $page, $this->per_page );
+                
</ins><span class="cx">                 $sql_for_translations = "
</span><span class="cx">                         SELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added
</span><span class="cx">                  FROM $gpdb->originals as o
</span></span></pre></div>
<a id="trunkgpincludesthingsuserphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/things/user.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/things/user.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-includes/things/user.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -117,7 +117,6 @@
</span><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                $key = gp_sanitize_meta_key( $key );
</del><span class="cx">                 if ( !isset( $user->$key ) ) {
</span><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="lines">@@ -139,4 +138,4 @@
</span><span class="cx">                 $wp_auth_object->users = $wp_users_object;
</span><span class="cx">         }
</span><span class="cx"> }
</span><del>-GP::$user = new GP_User();
</del><span class="cx">\ No newline at end of file
</span><ins>+GP::$user = new GP_User();
</ins></span></pre></div>
<a id="trunkgptemplatesheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-templates/header.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-templates/header.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-templates/header.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx">                         if (GP::$user->logged_in()):
</span><span class="cx">                                 $user = GP::$user->current();
</span><span class="cx">                                 
</span><del>-                                printf( __('Hi, %s.'), $user->user_login );
</del><ins>+                                printf( __('Hi, %s.'), '<a href="'.gp_url( '/profile' ).'">'.$user->user_login.'</a>' );
</ins><span class="cx">                                 ?>
</span><span class="cx">                                 <a href="<?php echo gp_url('/logout')?>"><?php _e('Log out'); ?></a>
</span><span class="cx">                         <?php else: ?>
</span></span></pre></div>
<a id="trunkgptemplatestranslationsphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-templates/translations.php (709 => 710)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-templates/translations.php        2012-10-30 23:15:43 UTC (rev 709)
+++ trunk/gp-templates/translations.php        2012-10-30 23:24:47 UTC (rev 710)
</span><span class="lines">@@ -94,7 +94,16 @@
</span><span class="cx">         <dl class="filters-expanded sort hidden clearfix">
</span><span class="cx">                 <dt><?php _e('By:'); ?></dt>
</span><span class="cx">                 <dd>
</span><del>-                <?php echo gp_radio_buttons('sort[by]',
</del><ins>+                <?php
+                $default_sort = GP::$user->current()->get_meta('default_sort');
+                if ( ! is_array($default_sort) ) {
+                        $default_sort = array(
+                                'by' => 'priority',
+                                'how' => 'desc'
+                        );
+                }
+                
+                echo gp_radio_buttons('sort[by]',
</ins><span class="cx">                         array(
</span><span class="cx">                                 'original_date_added' => __('Date added (original)'),
</span><span class="cx">                                 'translation_date_added' => __('Date added (translation)'),
</span><span class="lines">@@ -103,16 +112,16 @@
</span><span class="cx">                                 'priority' => __('Priority'),
</span><span class="cx">                                 'references' => __('Filename in source'),
</span><span class="cx">                                 'random' => __('Random'),
</span><del>-                        ), gp_array_get( $sort, 'by', 'priority' ) );
</del><ins>+                        ), gp_array_get( $sort, 'by', $default_sort['by'] ) );
</ins><span class="cx">                 ?>
</span><span class="cx">                 </dd>
</span><del>-                <dt><?php _e('How:'); ?></dt>
</del><ins>+                <dt><?php _e('Order:'); ?></dt>
</ins><span class="cx">                 <dd>
</span><span class="cx">                 <?php echo gp_radio_buttons('sort[how]',
</span><span class="cx">                         array(
</span><span class="cx">                                 'asc' => __('Ascending'),
</span><span class="cx">                                 'desc' => __('Descending'),
</span><del>-                        ), gp_array_get( $sort, 'how', 'desc' ) );
</del><ins>+                        ), gp_array_get( $sort, 'how', $default_sort['how'] ) );
</ins><span class="cx">                 ?>
</span><span class="cx">                 </dd>
</span><span class="cx">                 <dd><input type="submit" value="<?php echo esc_attr(__('Sort')); ?>" name="sorts" /></dd>
</span></span></pre>
</div>
</div>
</body>
</html>