Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .jules/Modernizer.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Modernizer — [Optimize table creation queries during install]
**Learning:** Found an N+1 query issue in `includes/functions-install.php` during the installation sequence, where table creation queries were executed in a loop. By batching them together using `implode` and sending a single `$ydb->perform` call, we significantly reduce execution time (observed ~83% reduction in local SQLite benchmark).
**Action:** Updated `yourls_create_sql_tables` in `includes/functions-install.php` to implode `$create_tables` array and perform a single batched SQL query execution, while keeping the return array logic intact.
## Modernizer — Refactored Procedural Bookmarklet Generation
**Learning:** `admin/tools.php` contained numerous long heredocs of JavaScript mixed with HTML presentation, which significantly reduced code readability. Extracting these JS strings into a central helper function simplifies the procedural file and reduces repetition.
**Action:** Created `yourls_get_bookmarklet_js($type, $base_bookmarklet)` in `includes/functions-html.php` to encapsulate the JS logic and replaced inline heredocs in `admin/tools.php` with concise function calls.
196 changes: 14 additions & 182 deletions admin/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,59 +62,15 @@
<th class="header"><?php yourls_e( 'Simple' ); ?></th>

<td>
<?php $js_code = <<<STANDARD_SIMPLE
// Simple Standard Bookmarklet (new page, no keyword asked)
var d = document,
w = window,
enc = encodeURIComponent,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : enc(s)),
f = '$base_bookmarklet',
l = d.location.href,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title)+'&s='+s2,
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u)) l.href = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
STANDARD_SIMPLE;
<?php
$js_code = yourls_get_bookmarklet_js( 'STANDARD_SIMPLE', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Shorten' ) );
?>
</td>

<td>
<?php $js_code = <<<POPUP_SIMPLE
// Simple Popup (in-page popup dialog, no keyword asked)
var d = document,
sc = d.createElement('script'),
l = d.location.href,
enc = encodeURIComponent,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title);
window.yourls_callback = function (r) {
if (r.short_url) {
prompt(r.message, r.short_url);
} else {
alert('An error occurred: ' + r.message);
}
};
sc.src = '$base_bookmarklet' + p + '&jsonp=yourls';
void(d.body.appendChild(sc));
POPUP_SIMPLE;
<?php
$js_code = yourls_get_bookmarklet_js( 'POPUP_SIMPLE', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Instant Shorten' ) );
?>
</td>
Expand All @@ -124,66 +80,15 @@
<th class="header"><?php yourls_e( 'Custom Keyword' ); ?></th>

<td>
<?php $js_code = <<<CUSTOM_STANDARD
// Custom Standard (new page, prompt for a keyword)
var d = document,
enc = encodeURIComponent,
w = window,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : enc(s)),
f = '$base_bookmarklet',
l = d.location.href,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
k = prompt("Custom URL"),
k2 = (k ? '&k=' + k : ""),
p = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title)+'&s='+s2 + k2,
u = f + p;
if (k != null) {
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u)) l = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0)
}
CUSTOM_STANDARD;
<?php
$js_code = yourls_get_bookmarklet_js( 'CUSTOM_STANDARD', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Custom shorten' ) );
?>
</td>

<td>
<?php $js_code = <<<CUSTOM_POPUP
// Custom Popup (prompt for a keyword + on-page popup)
var d = document,
l = d.location.href,
k = prompt('Custom URL'),
enc = encodeURIComponent,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up='+enc(ups[0]+':')+'&us='+enc(ups[1])+'&ur='+enc(ur)+'&t='+enc(d.title);
sc = d.createElement('script');
if (k != null) {
window.yourls_callback = function (r) {
if (r.short_url) {
prompt(r.message, r.short_url);
} else {
alert('An error occurred: ' + r.message);
}
};
sc.src = '$base_bookmarklet' + p + '&k=' + k + '&jsonp=yourls';
void(d.body.appendChild(sc));
}
CUSTOM_POPUP;
<?php
$js_code = yourls_get_bookmarklet_js( 'CUSTOM_POPUP', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'Instant Custom Shorten' ) );
?>
</td>
Expand All @@ -201,91 +106,18 @@
<p><?php yourls_e( 'Shorten and share:' ); ?></p>

<p>
<?php $js_code = <<<FACEBOOK
// Share on Facebook
var d = document,
enc = encodeURIComponent,
f = '$base_bookmarklet',
l = d.location.href,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur=' + enc(ur) + '&t=' + enc(d.title) + '&share=facebook',
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!window.open(u,'Share','width=500,height=340,left=100','_blank')) l.href = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
FACEBOOK;
<?php
$js_code = yourls_get_bookmarklet_js( 'FACEBOOK', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Facebook' ) );
?>

<?php $js_code = <<<TWITTER
// Share on Twitter
var d = document,
w = window,
enc = encodeURIComponent,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : '%20%22' + enc(s) + '%22'),
f = '$base_bookmarklet',
l = d.location.href,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur='+enc(ur) + '&t=' + enc(d.title) + s2 + '&share=twitter',
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u,'Share','width=780,height=265,left=100','_blank')) l = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
TWITTER;
<?php
$js_code = yourls_get_bookmarklet_js( 'TWITTER', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Twitter' ) );
?>

<?php $js_code = <<<TUMBLR
// Share on Tumblr
var d = document,
w = window,
enc = encodeURIComponent,
share = 'tumblr',
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : '%20%22' + enc(s) + '%22'),
f = '$base_bookmarklet',
l = d.location.href,
ups = l.match( /^[a-zA-Z0-9\+\.-]+:(\/\/)?/ )[0],
ur = l.split(new RegExp(ups))[1],
ups = ups.split(/\:/),
p = '?up=' + enc(ups[0]+':') + '&us=' + enc(ups[1]) + '&ur='+enc(ur) + '&t=' + enc(d.title) + '&s=' + s2 + '&share=tumblr',
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u,'Share','width=450,height=450,left=430','_blank')) l = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
TUMBLR;
<?php
$js_code = yourls_get_bookmarklet_js( 'TUMBLR', $base_bookmarklet );
yourls_bookmarklet_link( yourls_make_bookmarklet( $js_code ), yourls__( 'YOURLS &amp; Tumblr' ) );
?>

Expand Down
Loading
Loading