Skip to content

Commit

Permalink
shortener fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Sep 5, 2009
1 parent 91a61a6 commit 976614a
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/config/config.yml
Expand Up @@ -81,6 +81,7 @@ env:
- translate
- facebook
- pages
- shortener

installed:
- password
Expand All @@ -90,6 +91,7 @@ env:
- translate
- facebook
- pages
- shortener

boot: omb

Expand Down
30 changes: 28 additions & 2 deletions app/omb/plugins/wp.php
Expand Up @@ -669,6 +669,24 @@ function is_admin() {
return false;
}

function plugin_basename($file) {
$file = trim( $file, '/' );
return '';
}

function settings_fields() {

}

function checked() {
return false;
}

function selected() {
$vars = func_get_args();
if (count($vars) == 2 && ($vars[0] == $vars[1])) echo "SELECTED";
}

function _wp_filter_build_unique_id($tag, $function, $priority = 10){
global $wp_filter;

Expand Down Expand Up @@ -752,14 +770,19 @@ function bloginfo( $attr ) {
function get_option( $opt ) {
global $optiondata;
if (!isset($optiondata[$opt])){

global $db;
$Setting =& $db->model('Setting');
$s = $Setting->find_by(array('name'=>$opt,'profile_id'=>get_profile_id()));
if ($s)
if ($s) {
$un = unserialize($s->value);
if (is_array($un))
return $un;
echo $s->value; exit;
return $s->value;
}
return "";
}

$data = $optiondata[$opt];

if (strstr($data,"http") && "/" == substr($data,-1))
Expand Down Expand Up @@ -882,6 +905,9 @@ function wp_print_scripts( $scripts = false ) {
}
}

function wp_enqueue_style( $file1,$file2=NULL ) {
}

function wp_enqueue_script( $file1,$file2=NULL ) {
if (file_exists($file1))
require_once $file1;
Expand Down
177 changes: 177 additions & 0 deletions app/shortener/shortener.php
@@ -1,5 +1,36 @@
<?php

if (isset($_POST['ozh_yourls'])) {

if (!(signed_in()))
return;

$setting_name = 'ozh_yourls';
$setting_value = serialize($_POST['ozh_yourls']);
global $db,$request;

$Setting =& $db->model('Setting');

$sett = $Setting->find_by(array('name'=>$setting_name,'profile_id'=>get_profile_id()));

if (!$sett) {
$s = $Setting->base();
$s->set_value('profile_id',get_profile_id());
$s->set_value('person_id',get_person_id());
$s->set_value('name',$setting_name);
$s->set_value('value',$setting_value);
$s->save_changes();
$s->set_etag();
} else {
$sett->set_value('value',$setting_value);
$sett->save_changes();
}

$profile = get_profile();
redirect_to($request->url_for(array("resource"=>$profile->nickname))."/settings");

}

after_filter( 'set_up_new_shortener', 'insert_from_post' );

function set_up_new_shortener( &$model, &$rec ) {
Expand Down Expand Up @@ -178,7 +209,25 @@ function set_up_new_shortener( &$model, &$rec ) {


function shortener_init() {
include 'wp-content/language/lang_chooser.php'; //Loads the language-file
wp_plugin_include( 'yourls-wordpress-to-twitter' );

global $wp_ozh_yourls;
$filedir = "wp-content" . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR . 'yourls-wordpress-to-twitter';
require_once($filedir.'/inc/core.php');
require_once($filedir.'/inc/options.php');

if ( !defined('WP_CONTENT_URL') )
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
if ( !defined('WP_PLUGIN_DIR') )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
if ( !defined('WP_PLUGIN_URL') )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'.'/yourls-wordpress-to-twitter' );
if ( !defined('PLUGINDIR') )
define( 'PLUGINDIR', 'wp-content/plugins'.'/yourls-wordpress-to-twitter' );


app_register_init( 'shorteners', 'index.html', 'URL Shortener', 'shortener', 2 );
}

function shortener_show() {
Expand Down Expand Up @@ -212,3 +261,131 @@ function drop_all_blogs() {
}
}
}


function wp_ozh_yourls_omb_page() {
$plugin_url = WP_PLUGIN_URL.'/'.plugin_basename( dirname(dirname(__FILE__)) );
?>
<div class="wrap">

<?php /** ?>
<pre><?php print_r(get_option('ozh_yourls')); ?></pre>
<?php /**/ ?>

<form method="post" action="<?php base_url(); ?>">
<?php settings_fields('wp_ozh_yourls_options'); ?>
<?php $ozh_yourls = get_option('ozh_yourls'); ?>

<h3>URL Shortener Settings</h3>

<table class="form-table">

<tr valign="top">
<th scope="row">URL Shortener Service</th>
<td>

<label for="y_service">You are using:</label>
<select name="ozh_yourls[service]" id="y_service" class="y_toggle">
<option value="" <?php selected( '', $ozh_yourls['service'] ); ?> >Please select..</option>
<option value="yourls" <?php selected( 'yourls', $ozh_yourls['service'] ); ?> >your own YOURLS install</option>
<option value="other" <?php selected( 'other', $ozh_yourls['service'] ); ?> >another public service such as TinyURL or tr.im</option>
</select>

<?php $hidden = ( $ozh_yourls['service'] == 'yourls' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_yourls" class="<?php echo $hidden; ?> y_service y_level2">
<label for="y_location">Your YOURLS installation is</label>
<select name="ozh_yourls[location]" id="y_location" class="y_toggle">
<option value="" <?php selected( '', $ozh_yourls['location'] ); ?> >Please select...</option>
<option value="local" <?php selected( 'local', $ozh_yourls['location'] ); ?> >local, on the same webserver</option>
<option value="remote" <?php selected( 'remote', $ozh_yourls['location'] ); ?> >remote, on another webserver</option>
</select>

<?php $hidden = ( $ozh_yourls['location'] == 'local' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_local" class="<?php echo $hidden; ?> y_location y_level3">
<label for="y_path">Path to the YOURLS config file</label> <input type="text" class="y_longfield" id="y_path" name="ozh_yourls[yourls_path]" value="<?php echo $ozh_yourls['yourls_path']; ?>"/> <span id="y_test_path"></span><br/>
<em>Example: <tt>/home/you/site.com/yourls/includes/config.php</tt></em>
</div>

<?php $hidden = ( $ozh_yourls['location'] == 'remote' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_remote" class="<?php echo $hidden; ?> y_location y_level3">
<label for="y_url">URL to the YOURLS API</label> <input type="text" id="y_url" class="y_longfield" name="ozh_yourls[yourls_url]" value="<?php echo $ozh_yourls['yourls_url']; ?>"/> <span id="y_test_url"></span><br/>
<em>Example: <tt>http://site.com/yourls-api.php</tt></em><br/>
<label for="y_yourls_login">YOURLS Login</label> <input type="text" id="y_yourls_login" name="ozh_yourls[yourls_login]" value="<?php echo $ozh_yourls['yourls_login']; ?>"/><br/>
<label for="y_yourls_passwd">YOURLS Password</label> <input type="password" id="y_yourls_passwd" name="ozh_yourls[yourls_password]" value="<?php echo $ozh_yourls['yourls_password']; ?>"/><br/>
</div>

</div>

<?php $hidden = ( $ozh_yourls['service'] == 'other' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_other" class="<?php echo $hidden; ?> y_service y_level2">

<label for="y_other">Public service</label>
<select name="ozh_yourls[other]" id="y_other" class="y_toggle">
<option value="" <?php selected( '', $ozh_yourls['other'] ); ?> >Please select...</option>
<option value="trim" <?php selected( 'trim', $ozh_yourls['other'] ); ?> >tr.im</option>
<option value="rply" <?php selected( 'rply', $ozh_yourls['other'] ); ?> >rp.ly</option>
<!--<option value="pingfm" <?php selected( 'pingfm', $ozh_yourls['other'] ); ?> >ping.fm</option>-->
<option value="bitly" <?php selected( 'bitly', $ozh_yourls['other'] ); ?> >bit.ly</option>
<option value="tinyurl" <?php selected( 'tinyurl', $ozh_yourls['other'] ); ?> >tinyURL</option>
<option value="isgd" <?php selected( 'isgd', $ozh_yourls['other'] ); ?> >is.gd</option>
</select>

<?php $hidden = ( $ozh_yourls['other'] == 'bitly' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_bitly" class="<?php echo $hidden; ?> y_other y_level3">
<label for="y_api_bitly_login">API Login</label> <input type="text" id="y_api_bitly_login" name="ozh_yourls[bitly_login]" value="<?php echo $ozh_yourls['bitly_login']; ?>"/> (case sensitive!)<br/>
<label for="y_api_bitly_pass">API Key</label> <input type="text" id="y_api_bitly_pass" class="y_longfield" name="ozh_yourls[bitly_password]" value="<?php echo $ozh_yourls['bitly_password']; ?>"/><br/>
<em>If you have a <a href="http://bit.ly/account/">bit.ly</a> account, entering your credentials will link the short URLs to it</em>
</div>

<?php $hidden = ( $ozh_yourls['other'] == 'trim' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_trim" class="<?php echo $hidden; ?> y_other y_level3">
<label for="y_api_trim_login">Username</label> <input type="text" id="y_api_trim_login" name="ozh_yourls[trim_login]" value="<?php echo $ozh_yourls['trim_login']; ?>"/><br/>
<label for="y_api_trim_pass">Password</label> <input type="password" id="y_api_trim_pass" name="ozh_yourls[trim_password]" value="<?php echo $ozh_yourls['trim_password']; ?>"/><br/>
<em>If you have a <a href="http://tr.im/">tr.im</a> account, entering your credentials will link the short URLs to it</em>
</div>

<?php $hidden = ( $ozh_yourls['other'] == 'rply' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_rply" class="<?php echo $hidden; ?> y_other y_level3">
<label for="y_api_rply_login">Username</label> <input type="text" id="y_api_rply_login" name="ozh_yourls[rply_login]" value="<?php echo $ozh_yourls['rply_login']; ?>"/><br/>
<label for="y_api_rply_pass">Password</label> <input type="password" id="y_api_rply_pass" name="ozh_yourls[rply_password]" value="<?php echo $ozh_yourls['rply_password']; ?>"/><br/>
<em>If you have a <a href="http://rp.ly/">rp.ly</a> account, entering your credentials will link the short URLs to it</em>
</div>

<?php $hidden = ( $ozh_yourls['other'] == 'pingfm' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_pingfm" class="<?php echo $hidden; ?> y_other y_level3">
<label for="y_api_pingfm_user_app_key">Web Key</label> <input type="text" id="y_api_pingfm_user_app_key" name="ozh_yourls[pingfm_user_app_key]" value="<?php echo $ozh_yourls['pingfm_user_app_key']; ?>"/><br/>
<em>If you have a <a href="http://ping.fm/">ping.fm</a> account, enter your private <a href="http://ping.fm/key/">Web Key</a></em>
</div>

<?php $hidden = ( $ozh_yourls['other'] == 'tinyurl' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_tinyurl" class="<?php echo $hidden; ?> y_other y_level3">
<em>(this service needs no authentication)</em>
</div>


<?php $hidden = ( $ozh_yourls['other'] == 'isgd' ? '' : 'y_hidden' ) ; ?>
<div id="y_show_isgd" class="<?php echo $hidden; ?> y_other y_level3">
<em>(this service needs no authentication)</em>
</div>

</div>

</td>
</tr>
</table>




<p class="submit">
<input type="submit" class="button-primary omb_submit" value="<?php _e('Save Changes') ?>" />
</p>

</form>

</div> <!-- wrap -->


<?php
}

5 changes: 5 additions & 0 deletions db/library/dbscript/_functions.php
Expand Up @@ -1348,6 +1348,11 @@ function wp_plugin_include( $file, $basedir=NULL ) {
require_once $startfile;
return;
}
$startfile = $wp_plugins.DIRECTORY_SEPARATOR.'plugin.php';
if (is_file($startfile)) {
require_once $startfile;
return;
}
}


Expand Down
26 changes: 26 additions & 0 deletions wp-content/themes/p2/header.php
Expand Up @@ -75,8 +75,34 @@ function inline_comment(postid,parentid) {
});
$(".editable_comment").trigger('click');
}
function inline_shorturl() {
var submit_to = "http://megapump.com";
$("#shorturl").html('<p class="editable_comment" id="shorten"></p>');
$("#shorten").editable(submit_to, {
indicator : "<img src=\''. base_path(true).'resource/jeditable/indicator.gif\'>",
submitdata : function() {
return {"method":"post"};
},
name : "url",
type : "textarea",
noappend : "true",
submit : "OK",
tooltip : "",
cancel : "Cancel",
callback : function(value, settings) {
$("#shorturl").html('<p>Add:&nbsp; <a href="JavaScript:inline_shorturl();">Link</a></p>');
return(value);
}
});
$("#shorten").trigger('click');
}
</script>
<style type="text/css">
#shorten {
width:380px;
height:20px;
padding-bottom:35px;
}
.editable_comment {
width:380px;
height:40px;
Expand Down
7 changes: 6 additions & 1 deletion wp-content/themes/p2/post-form.php
Expand Up @@ -37,4 +37,9 @@
<p>Add:&nbsp; <a href="<?php url_for(array('resource'=>'posts','action'=>'upload')); ?>">File</a></p>
<?php endif; ?>
<?php endif; ?>
</div> <!-- // postbox -->
<div id="shorturl"><p>Add:&nbsp; <a href="JavaScript:inline_shorturl();">Link</a></p></div>
</div> <!-- // postbox -->




0 comments on commit 976614a

Please sign in to comment.