Exemple #1
0
<?php

define('YOURLS_ADMIN', true);
define('YOURLS_INSTALLING', true);
require_once dirname(dirname(__FILE__)) . '/includes/load-yourls.php';
require_once YOURLS_INC . '/functions-install.php';
$error = array();
$warning = array();
$success = array();
// Check pre-requisites
if (!yourls_check_database_version()) {
    $error[] = yourls_s('%s version is too old. Ask your server admin for an upgrade.', 'MySQL');
    yourls_debug_log('MySQL version: ' . yourls_get_database_version());
}
if (!yourls_check_php_version()) {
    $error[] = yourls_s('%s version is too old. Ask your server admin for an upgrade.', 'PHP');
    yourls_debug_log('PHP version: ' . phpversion());
}
// Is YOURLS already installed ?
if (yourls_is_installed()) {
    $error[] = yourls__('YOURLS already installed.');
    // check if .htaccess exists, recreate otherwise. No error checking.
    if (!file_exists(YOURLS_ABSPATH . '/.htaccess')) {
        yourls_create_htaccess();
    }
}
// Start install if possible and needed
if (isset($_REQUEST['install']) && count($error) == 0) {
    // Create/update .htaccess file
    if (yourls_create_htaccess()) {
        $success[] = yourls__('File <tt>.htaccess</tt> successfully created/updated.');
        echo sprintf(yourls_n('<strong>%1$s</strong> hit on %2$s', '<strong>%1$s</strong> hits on %2$s', $best['max']), $best['max'], yourls_date_i18n("F j, Y", strtotime($best['day'])));
        ?>
. 
				<a href="" class='details hide-if-no-js' id="more_clicks"><?php 
        yourls_e('Click for more details');
        ?>
</a></p>
				<ul id="details_clicks" style="display:none">
					<?php 
        foreach ($dates as $year => $months) {
            $css_year = $year == $best_time['year'] ? 'best_year' : '';
            if (count($list_of_years) > 1) {
                $li = "<a href='' class='details' id='more_year{$year}'>" . yourls_s('Year %s', $year) . '</a>';
                $display = 'none';
            } else {
                $li = yourls_s('Year %s', $year);
                $display = 'block';
            }
            echo "<li><span class='{$css_year}'>{$li}</span>";
            echo "<ul style='display:{$display}' id='details_year{$year}'>";
            foreach ($months as $month => $days) {
                $css_month = $month == $best_time['month'] && $css_year == 'best_year' ? 'best_month' : '';
                $monthname = yourls_date_i18n("F", mktime(0, 0, 0, $month, 1));
                if (count($list_of_months) > 1) {
                    $li = "<a href='' class='details' id='more_month{$year}{$month}'>{$monthname}</a>";
                    $display = 'none';
                } else {
                    $li = "{$monthname}";
                    $display = 'block';
                }
                echo "<li><span class='{$css_month}'>{$li}</span>";
/**
 * Create MySQL tables. Return array( 'success' => array of success strings, 'errors' => array of error strings )
 *
 * @since 1.3
 * @return array  An array like array( 'success' => array of success strings, 'errors' => array of error strings )
 */
function yourls_create_sql_tables()
{
    // Allow plugins (most likely a custom db.php layer in user dir) to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_yourls_create_sql_tables', null);
    // your filter function should return an array of ( 'success' => $success_msg, 'error' => $error_msg ), see below
    if (null !== $pre) {
        return $pre;
    }
    global $ydb;
    $error_msg = array();
    $success_msg = array();
    // Create Table Query
    $create_tables = array();
    $create_tables[YOURLS_DB_TABLE_URL] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_URL . '` (' . '`keyword` varchar(200) BINARY NOT NULL,' . '`url` text BINARY NOT NULL,' . '`title` text CHARACTER SET utf8,' . '`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,' . '`ip` VARCHAR(41) NOT NULL,' . '`clicks` INT(10) UNSIGNED NOT NULL,' . ' PRIMARY KEY  (`keyword`),' . ' KEY `timestamp` (`timestamp`),' . ' KEY `ip` (`ip`)' . ');';
    $create_tables[YOURLS_DB_TABLE_OPTIONS] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_OPTIONS . '` (' . '`option_id` bigint(20) unsigned NOT NULL auto_increment,' . '`option_name` varchar(64) NOT NULL default "",' . '`option_value` longtext NOT NULL,' . 'PRIMARY KEY  (`option_id`,`option_name`),' . 'KEY `option_name` (`option_name`)' . ') AUTO_INCREMENT=1 ;';
    $create_tables[YOURLS_DB_TABLE_LOG] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_LOG . '` (' . '`click_id` int(11) NOT NULL auto_increment,' . '`click_time` datetime NOT NULL,' . '`shorturl` varchar(200) BINARY NOT NULL,' . '`referrer` varchar(200) NOT NULL,' . '`user_agent` varchar(255) NOT NULL,' . '`ip_address` varchar(41) NOT NULL,' . '`country_code` char(2) NOT NULL,' . 'PRIMARY KEY  (`click_id`),' . 'KEY `shorturl` (`shorturl`)' . ') AUTO_INCREMENT=1 ;';
    $create_table_count = 0;
    $ydb->show_errors = true;
    // Create tables
    foreach ($create_tables as $table_name => $table_query) {
        $ydb->query($table_query);
        $create_success = $ydb->query("SHOW TABLES LIKE '{$table_name}'");
        if ($create_success) {
            $create_table_count++;
            $success_msg[] = yourls_s("Table '%s' created.", $table_name);
        } else {
            $error_msg[] = yourls_s("Error creating table '%s'.", $table_name);
        }
    }
    // Initializes the option table
    if (!yourls_initialize_options()) {
        $error_msg[] = yourls__('Could not initialize options');
    }
    // Insert sample links
    if (!yourls_insert_sample_links()) {
        $error_msg[] = yourls__('Could not insert sample short URLs');
    }
    // Check results of operations
    if (sizeof($create_tables) == $create_table_count) {
        $success_msg[] = yourls__('YOURLS tables successfully created.');
    } else {
        $error_msg[] = yourls__('Error creating YOURLS tables.');
    }
    return array('success' => $success_msg, 'error' => $error_msg);
}
Exemple #4
0
                // share with Facebook
                $destination = sprintf("https://www.facebook.com/sharer/sharer.php?u=%s&t=%s", urlencode($return['shorturl']), urlencode($title));
                yourls_redirect($destination, 303);
                // Deal with the case when redirection failed:
                $return['status'] = 'error';
                $return['errorCode'] = 400;
                $return['message'] = yourls_s('Short URL created, but could not redirect to %s !', 'Facebook');
                break;
            case 'tumblr':
                // share with Tumblr
                $destination = sprintf("https://www.tumblr.com/share?v=3&u=%s&t=%s&s=%s", urlencode($return['shorturl']), urlencode($title), urlencode($text));
                yourls_redirect($destination, 303);
                // Deal with the case when redirection failed:
                $return['status'] = 'error';
                $return['errorCode'] = 400;
                $return['message'] = yourls_s('Short URL created, but could not redirect to %s !', 'Tumblr');
                break;
            default:
                // Is there a custom registered social bookmark?
                yourls_do_action('share_redirect_' . $_GET['share'], $return);
                // Still here? That was an unknown 'share' method, then.
                $return['status'] = 'error';
                $return['errorCode'] = 400;
                $return['message'] = yourls__('Unknown "Share" bookmarklet');
                break;
        }
    }
    // This is not a bookmarklet
} else {
    $is_bookmark = false;
    // Checking $page, $offset, $perpage
Exemple #5
0
/**
 * Display a notice if there is a newer version of YOURLS available
 *
 * @since 1.7
 */
function yourls_new_core_version_notice()
{
    yourls_debug_log('Check for new version: ' . (yourls_maybe_check_core_version() ? 'yes' : 'no'));
    $checks = yourls_get_option('core_version_checks');
    if (isset($checks->last_result->latest) and version_compare($checks->last_result->latest, YOURLS_VERSION, '>')) {
        $msg = yourls_s('<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $checks->last_result->latest);
        yourls_add_notice($msg);
    }
}
Exemple #6
0
/**
 * Activate a plugin
 *
 * @param string $plugin Plugin filename (full or relative to plugins directory)
 * @return mixed string if error or true if success
 */
function yourls_activate_plugin($plugin)
{
    // validate file
    $plugin = yourls_plugin_basename($plugin);
    $plugindir = yourls_sanitize_filename(YOURLS_PLUGINDIR);
    if (!yourls_validate_plugin_file($plugindir . '/' . $plugin)) {
        return yourls__('Not a valid plugin file');
    }
    // check not activated already
    global $ydb;
    if (yourls_has_active_plugins() && in_array($plugin, $ydb->plugins)) {
        return yourls__('Plugin already activated');
    }
    // attempt activation. TODO: uber cool fail proof sandbox like in WP.
    ob_start();
    include YOURLS_PLUGINDIR . '/' . $plugin;
    if (ob_get_length() > 0) {
        // there was some output: error
        $output = ob_get_clean();
        return yourls_s('Plugin generated unexpected output. Error was: <br/><pre>%s</pre>', $output);
    }
    // so far, so good: update active plugin list
    $ydb->plugins[] = $plugin;
    yourls_update_option('active_plugins', $ydb->plugins);
    yourls_do_action('activated_plugin', $plugin);
    yourls_do_action('activated_' . $plugin);
    return true;
}
Exemple #7
0
 * The following code is a shim that helps users store passwords securely in config.php
 * by storing a password hash and removing the plaintext.
 *
 * TODO: Remove this once real user management is implemented
 */
// Did we just fail at encrypting passwords ?
if (isset($_GET['dismiss']) && $_GET['dismiss'] == 'hasherror') {
    yourls_update_option('defer_hashing_error', time() + 86400 * 7);
    // now + 1 week
} else {
    // Encrypt passwords that are clear text
    if (!defined('YOURLS_NO_HASH_PASSWORD') && yourls_has_cleartext_passwords()) {
        $hash = yourls_hash_passwords_now(YOURLS_CONFIGFILE);
        if ($hash === true) {
            // Hashing succesful. Remove flag from DB if any.
            if (yourls_get_option('defer_hashing_error')) {
                yourls_delete_option('defer_hashing_error');
            }
        } else {
            // It failed, display message for first time or if last time was a week ago
            if (time() > yourls_get_option('defer_hashing_error') or !yourls_get_option('defer_hashing_error')) {
                $message = yourls_s('Could not auto-encrypt passwords. Error was: "%s".', $hash);
                $message .= ' ';
                $message .= yourls_s('<a href="%s">Get help</a>.', 'http://yourls.org/userpassword');
                $message .= '</p><p>';
                $message .= yourls_s('<a href="%s">Click here</a> to dismiss this message for one week.', '?dismiss=hasherror');
                yourls_add_notice($message);
            }
        }
    }
}
Exemple #8
0
/**
 * Redirect to another page using Javascript. Set optional (bool)$dontwait to false to force manual redirection (make sure a message has been read by user)
 *
 */
function yourls_redirect_javascript($location, $dontwait = true)
{
    yourls_do_action('pre_redirect_javascript', $location, $dontwait);
    $location = yourls_apply_filter('redirect_javascript', $location, $dontwait);
    if ($dontwait) {
        $message = yourls_s('if you are not redirected after 10 seconds, please <a href="%s">click here</a>', $location);
        echo <<<REDIR
\t\t<script type="text/javascript">
\t\twindow.location="{$location}";
\t\t</script>
\t\t<small>({$message})</small>
REDIR;
    } else {
        echo '<p>' . yourls_s('Please <a href="%s">click here</a>', $location) . '</p>';
    }
    yourls_do_action('post_redirect_javascript', $location);
}
Exemple #9
0
/**
 * Echo a translated sprintf() string (mix yourls__() and sprintf() in one func)
 *
 * Instead of doing printf( yourls__( 'string %s' ), $arg ) you can simply use:
 * yourls_se( 'string %s', $arg )
 * This function accepts an arbitrary number of arguments:
 * - first one will be the string to translate, eg "hello %s my name is %s"
 * - following ones will be the sprintf arguments, eg "world" and "Ozh"
 * - if there are more arguments passed than needed, the last one will be used as the translation domain
 *
 * @see yourls_s()
 * @see sprintf()
 * @since 1.6
 *
 * @param string $text Text to translate
 * @param string $arg1, $arg2... Optional: sprintf tokens, and translation domain
 * @return string Translated text
 */
function yourls_se($pattern)
{
    echo yourls_s(func_get_args());
}
Exemple #10
0
</p>
			<p><?php 
            yourls_e("On every step, if <span class='error'>something goes wrong</span>, you'll see a message and hopefully a way to fix.");
            ?>
</p>
			<p><?php 
            yourls_e('If everything goes too fast and you cannot read, <span class="success">good for you</span>, let it go :)');
            ?>
</p>
			<p><?php 
            yourls_e('Once you are ready, press "Upgrade" !');
            ?>
</p>
			<?php 
            echo "\n\t\t\t<form action='upgrade.php?' method='get'>\n\t\t\t<input type='hidden' name='step' value='1' />\n\t\t\t<input type='hidden' name='oldver' value='{$oldver}' />\n\t\t\t<input type='hidden' name='newver' value='{$newver}' />\n\t\t\t<input type='hidden' name='oldsql' value='{$oldsql}' />\n\t\t\t<input type='hidden' name='newsql' value='{$newsql}' />\n\t\t\t<input type='submit' class='primary' value='" . yourls_esc_attr__('Upgrade') . "' />\n\t\t\t</form>";
            break;
        case 1:
        case 2:
            $upgrade = yourls_upgrade($step, $oldver, $newver, $oldsql, $newsql);
            break;
        case 3:
            $upgrade = yourls_upgrade(3, $oldver, $newver, $oldsql, $newsql);
            echo '<p>' . yourls__('Your installation is now up to date ! ') . '</p>';
            echo '<p>' . yourls_s('Go back to <a href="%s">the admin interface</a>', yourls_admin_url('index.php')) . '</p>';
    }
}
?>
	

<?php 
yourls_html_footer();
Exemple #11
0
/**
 * Create MySQL tables. Return array( 'success' => array of success strings, 'errors' => array of error strings )
 *
 */
function yourls_create_sql_tables()
{
    global $ydb;
    $error_msg = array();
    $success_msg = array();
    // Create Table Query
    $create_tables = array();
    $create_tables[YOURLS_DB_TABLE_URL] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_URL . '` (' . '`keyword` varchar(200) BINARY NOT NULL,' . '`url` text BINARY NOT NULL,' . '`title` text CHARACTER SET utf8,' . '`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,' . '`ip` VARCHAR(41) NOT NULL,' . '`clicks` INT(10) UNSIGNED NOT NULL,' . ' PRIMARY KEY  (`keyword`),' . ' KEY `timestamp` (`timestamp`),' . ' KEY `ip` (`ip`)' . ');';
    $create_tables[YOURLS_DB_TABLE_OPTIONS] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_OPTIONS . '` (' . '`option_id` bigint(20) unsigned NOT NULL auto_increment,' . '`option_name` varchar(64) NOT NULL default "",' . '`option_value` longtext NOT NULL,' . 'PRIMARY KEY  (`option_id`,`option_name`),' . 'KEY `option_name` (`option_name`)' . ') AUTO_INCREMENT=1 ;';
    $create_tables[YOURLS_DB_TABLE_LOG] = 'CREATE TABLE IF NOT EXISTS `' . YOURLS_DB_TABLE_LOG . '` (' . '`click_id` int(11) NOT NULL auto_increment,' . '`click_time` datetime NOT NULL,' . '`shorturl` varchar(200) BINARY NOT NULL,' . '`referrer` varchar(200) NOT NULL,' . '`user_agent` varchar(255) NOT NULL,' . '`ip_address` varchar(41) NOT NULL,' . '`country_code` char(2) NOT NULL,' . 'PRIMARY KEY  (`click_id`),' . 'KEY `shorturl` (`shorturl`)' . ') AUTO_INCREMENT=1 ;';
    $create_table_count = 0;
    $ydb->show_errors = true;
    // Create tables
    foreach ($create_tables as $table_name => $table_query) {
        $ydb->query($table_query);
        $create_success = $ydb->query("SHOW TABLES LIKE '{$table_name}'");
        if ($create_success) {
            $create_table_count++;
            $success_msg[] = yourls_s("Table '%s' created.", $table_name);
        } else {
            $error_msg[] = yourls_s("Error creating table '%s'.", $table_name);
        }
    }
    // Insert data into tables
    yourls_update_option('version', YOURLS_VERSION);
    yourls_update_option('db_version', YOURLS_DB_VERSION);
    yourls_update_option('next_id', 1);
    // Insert sample links
    yourls_insert_link_in_db('http://planetozh.com/blog/', 'ozhblog', 'planetOzh: Ozh\' blog');
    yourls_insert_link_in_db('http://ozh.org/', 'ozh', 'ozh.org');
    yourls_insert_link_in_db('http://yourls.org/', 'yourls', 'YOURLS: Your Own URL Shortener');
    // Check results of operations
    if (sizeof($create_tables) == $create_table_count) {
        $success_msg[] = yourls__('YOURLS tables successfully created.');
    } else {
        $error_msg[] = yourls__('Error creating YOURLS tables.');
    }
    return array('success' => $success_msg, 'error' => $error_msg);
}
Exemple #12
0
        $class = 'active';
        $action_url = yourls_nonce_url('manage_plugins', yourls_add_query_arg(array('action' => 'deactivate', 'plugin' => $plugindir)));
        $action_anchor = yourls__('Deactivate');
    } else {
        $class = 'inactive';
        $action_url = yourls_nonce_url('manage_plugins', yourls_add_query_arg(array('action' => 'activate', 'plugin' => $plugindir)));
        $action_anchor = yourls__('Activate');
    }
    // Other "Fields: Value" in the header? Get them too
    if ($plugin) {
        foreach ($plugin as $extra_field => $extra_value) {
            $data['desc'] .= "<br/>\n<em>{$extra_field}</em>: {$extra_value}";
            unset($plugin[$extra_value]);
        }
    }
    $data['desc'] .= '<br/><small>' . yourls_s('plugin file location: %s', $file) . '</small>';
    printf("<tr class='plugin %s'><td class='plugin_name'><a href='%s'>%s</a></td><td class='plugin_version'>%s</td><td class='plugin_desc'>%s</td><td class='plugin_author'><a href='%s'>%s</a></td><td class='plugin_actions actions'><a href='%s'>%s</a></td></tr>", $class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor);
}
?>
	</tbody>
	</table>
	
	<script type="text/javascript">
	yourls_defaultsort = 0;
	yourls_defaultorder = 0;
	<?php 
if ($count_active) {
    ?>
	$('#plugin_summary').append('<span id="toggle_plugins">filter</span>');
	$('#toggle_plugins').css({'background':'transparent url("../images/filter.gif") top left no-repeat','display':'inline-block','text-indent':'-9999px','width':'16px','height':'16px','margin-left':'3px','cursor':'pointer'})
		.attr('title', '<?php 
Exemple #13
0
/**
 * Display HTML footer (including closing body & html tags)
 *
 */
function yourls_html_footer()
{
    global $ydb;
    $num_queries = sprintf(yourls_n('1 query', '%s queries', $ydb->num_queries), $ydb->num_queries);
    ?>
	</div> <?php 
    // wrap
    ?>
	<div id="footer"><p>
		<?php 
    $footer = yourls_s('Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION);
    $footer .= ' &ndash; ' . $num_queries;
    echo yourls_apply_filters('html_footer_text', $footer);
    ?>
	</p></div>
	<?php 
    if (defined('YOURLS_DEBUG') && YOURLS_DEBUG == true) {
        echo '<p>' . $ydb->all_queries . '<p>';
    }
    ?>
	<?php 
    yourls_do_action('html_footer', $ydb->context);
    ?>
	</body>
	</html>
	<?php 
}