+
+function common_copy_args($from) {
+ $to = array();
+ $strip = get_magic_quotes_gpc();
+ foreach ($from as $k => $v) {
+ $to[$k] = ($strip) ? stripslashes($v) : $v;
+ }
+ return $to;
+}
+
+function common_user_uri(&$user) {
+ return common_local_url('userbyid', array('id' => $user->id));
+}
+
+function common_notice_uri(&$notice) {
+ return common_local_url('shownotice',
+ array('notice' => $notice->id));
+}
+
+# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
+
+function common_confirmation_code($bits) {
+ # 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
+ static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
+ $chars = ceil($bits/5);
+ $code = '';
+ for ($i = 0; $i < $chars; $i++) {
+ # XXX: convert to string and back
+ $num = hexdec(common_good_rand(1));
+ # XXX: randomness is too precious to throw away almost
+ # 40% of the bits we get!
+ $code .= $codechars[$num%32];
+ }
+ return $code;
+}
+
+# convert markup to HTML
+
+function common_markup_to_html($c) {
+ $c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c);
+ $c = preg_replace('/%%doc.(\w+)%%/e', "common_local_url('doc', array('title'=>'\\1'))", $c);
+ $c = preg_replace('/%%(\w+).(\w+)%%/e', 'common_config(\'\\1\', \'\\2\')', $c);
+ return Markdown($c);
+}
+
+function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) {
+ $avatar = $profile->getAvatar($size);
+ if ($avatar) {
+ return common_avatar_display_url($avatar);
+ } else {
+ return common_default_avatar($size);
+ }
+}
+
+function common_profile_uri($profile) {
+ if (!$profile) {
+ return NULL;
+ }
+ $user = User::staticGet($profile->id);
+ if ($user) {
+ return $user->uri;
+ }
+
+ $remote = Remote_profile::staticGet($profile->id);
+ if ($remote) {
+ return $remote->uri;
+ }
+ # XXX: this is a very bad profile!
+ return NULL;
+}
\ No newline at end of file