aboutsummaryrefslogtreecommitdiffstats
path: root/mod/profiles.php
diff options
context:
space:
mode:
authorZach Prezkuta <fermion@gmx.com>2013-01-06 14:42:51 -0700
committerZach Prezkuta <fermion@gmx.com>2013-01-06 15:57:11 -0700
commita0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468 (patch)
tree280d792355cb2e60cf62e8451b6d8afbbfcc7c0d /mod/profiles.php
parent61b8ea9e1af74e2056e18b02c170a899de9abd1b (diff)
downloadvolse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.tar.gz
volse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.tar.bz2
volse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.zip
implement Smarty3
Diffstat (limited to 'mod/profiles.php')
-rw-r--r--mod/profiles.php278
1 files changed, 156 insertions, 122 deletions
diff --git a/mod/profiles.php b/mod/profiles.php
index 37be9bd08..5b2102852 100644
--- a/mod/profiles.php
+++ b/mod/profiles.php
@@ -1,6 +1,162 @@
<?php
+function profiles_init(&$a) {
+
+ nav_set_selected('profiles');
+
+ if(! local_user()) {
+ return;
+ }
+
+ if((argc() > 2) && (argv(1) === "drop") && intval(argv(2))) {
+ $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1",
+ intval($a->argv[2]),
+ intval(local_user())
+ );
+ if(! count($r)) {
+ notice( t('Profile not found.') . EOL);
+ goaway($a->get_baseurl(true) . '/profiles');
+ return; // NOTREACHED
+ }
+ $profile_guid = $r['profile_guid'];
+
+ check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
+
+ // move every contact using this profile as their default to the user default
+
+ $r = q("UPDATE abook SET abook_profile = (SELECT profile_guid AS FROM profile WHERE is_default = 1 AND uid = %d LIMIT 1) WHERE abook_profile = '%s' AND abook_channel = %d ",
+ intval(local_user()),
+ dbesc($profile_guid),
+ intval(local_user())
+ );
+ $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval(argv(2)),
+ intval(local_user())
+ );
+ if($r)
+ info( t('Profile deleted.') . EOL);
+
+ goaway($a->get_baseurl(true) . '/profiles');
+ return; // NOTREACHED
+ }
+
+
+
+
+
+ if((argc() > 1) && (argv(1) === 'new')) {
+
+ check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
+
+ $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
+ intval(local_user()));
+ $num_profiles = count($r0);
+
+ $name = t('Profile-') . ($num_profiles + 1);
+
+ $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is_default` = 1 LIMIT 1",
+ intval(local_user()));
+
+ $r2 = q("INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`)
+ VALUES ( %d, '%s', '%s', '%s', '%s' )",
+ intval(get_account_id()),
+ intval(local_user()),
+ dbesc(random_string()),
+ dbesc($name),
+ dbesc($r1[0]['name']),
+ dbesc($r1[0]['photo']),
+ dbesc($r1[0]['thumb'])
+ );
+
+ $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1",
+ intval(local_user()),
+ dbesc($name)
+ );
+
+ info( t('New profile created.') . EOL);
+ if(count($r3) == 1)
+ goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
+
+ goaway($a->get_baseurl(true) . '/profiles');
+ }
+
+ if((argc() > 2) && (argv(1) === 'clone')) {
+
+ check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
+
+ $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
+ intval(local_user()));
+ $num_profiles = count($r0);
+
+ $name = t('Profile-') . ($num_profiles + 1);
+ $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ intval(local_user()),
+ intval($a->argv[2])
+ );
+ if(! count($r1)) {
+ notice( t('Profile unavailable to clone.') . EOL);
+ $a->error = 404;
+ return;
+ }
+ unset($r1[0]['id']);
+ $r1[0]['is_default'] = 0;
+ $r1[0]['publish'] = 0;
+ $r1[0]['profile_name'] = dbesc($name);
+ $r1[0]['profile_guid'] = dbesc(random_string());
+
+ dbesc_array($r1[0]);
+
+ $r2 = dbq("INSERT INTO `profile` (`"
+ . implode("`, `", array_keys($r1[0]))
+ . "`) VALUES ('"
+ . implode("', '", array_values($r1[0]))
+ . "')" );
+
+ $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1",
+ intval(local_user()),
+ dbesc($name)
+ );
+ info( t('New profile created.') . EOL);
+ if(count($r3) == 1)
+ goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
+
+ goaway($a->get_baseurl(true) . '/profiles');
+
+ return; // NOTREACHED
+ }
+
+
+ // Run profile_load() here to make sure the theme is set before
+ // we start loading content
+ if((argc() > 1) && (intval(argv(1)))) {
+ $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($a->argv[1]),
+ intval(local_user())
+ );
+ if(! count($r)) {
+ notice( t('Profile not found.') . EOL);
+ $a->error = 404;
+ return;
+ }
+
+ $chan = $a->get_channel();
+
+ profile_load($a,$chan['channel_address'],$r[0]['id']);
+ }
+}
+
+function profiles_aside(&$a) {
+
+ if(! local_user()) {
+ return;
+ }
+
+ if((argc() > 1) && (intval(argv(1)))) {
+ profile_aside($a);
+ }
+}
+
function profiles_post(&$a) {
if(! local_user()) {
@@ -307,130 +463,12 @@ function profiles_post(&$a) {
function profiles_content(&$a) {
$o = '';
- nav_set_selected('profiles');
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
- if((argc() > 2) && (argv(1) === "drop") && intval(argv(2))) {
- $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1",
- intval($a->argv[2]),
- intval(local_user())
- );
- if(! count($r)) {
- notice( t('Profile not found.') . EOL);
- goaway($a->get_baseurl(true) . '/profiles');
- return; // NOTREACHED
- }
- $profile_guid = $r['profile_guid'];
-
- check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
-
- // move every contact using this profile as their default to the user default
-
- $r = q("UPDATE abook SET abook_profile = (SELECT profile_guid AS FROM profile WHERE is_default = 1 AND uid = %d LIMIT 1) WHERE abook_profile = '%s' AND abook_channel = %d ",
- intval(local_user()),
- dbesc($profile_guid),
- intval(local_user())
- );
- $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval(argv(2)),
- intval(local_user())
- );
- if($r)
- info( t('Profile deleted.') . EOL);
-
- goaway($a->get_baseurl(true) . '/profiles');
- return; // NOTREACHED
- }
-
-
-
-
-
- if((argc() > 1) && (argv(1) === 'new')) {
-
- check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
-
- $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
- intval(local_user()));
- $num_profiles = count($r0);
-
- $name = t('Profile-') . ($num_profiles + 1);
-
- $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is_default` = 1 LIMIT 1",
- intval(local_user()));
-
- $r2 = q("INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`)
- VALUES ( %d, '%s', '%s', '%s', '%s' )",
- intval(get_account_id()),
- intval(local_user()),
- dbesc(random_string()),
- dbesc($name),
- dbesc($r1[0]['name']),
- dbesc($r1[0]['photo']),
- dbesc($r1[0]['thumb'])
- );
-
- $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1",
- intval(local_user()),
- dbesc($name)
- );
-
- info( t('New profile created.') . EOL);
- if(count($r3) == 1)
- goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
-
- goaway($a->get_baseurl(true) . '/profiles');
- }
-
- if((argc() > 2) && (argv(1) === 'clone')) {
-
- check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
-
- $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
- intval(local_user()));
- $num_profiles = count($r0);
-
- $name = t('Profile-') . ($num_profiles + 1);
- $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
- intval(local_user()),
- intval($a->argv[2])
- );
- if(! count($r1)) {
- notice( t('Profile unavailable to clone.') . EOL);
- return;
- }
- unset($r1[0]['id']);
- $r1[0]['is_default'] = 0;
- $r1[0]['publish'] = 0;
- $r1[0]['profile_name'] = dbesc($name);
- $r1[0]['profile_guid'] = dbesc(random_string());
-
- dbesc_array($r1[0]);
-
- $r2 = dbq("INSERT INTO `profile` (`"
- . implode("`, `", array_keys($r1[0]))
- . "`) VALUES ('"
- . implode("', '", array_values($r1[0]))
- . "')" );
-
- $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1",
- intval(local_user()),
- dbesc($name)
- );
- info( t('New profile created.') . EOL);
- if(count($r3) == 1)
- goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
-
- goaway($a->get_baseurl(true) . '/profiles');
-
- return; // NOTREACHED
- }
-
-
if((argc() > 1) && (intval(argv(1)))) {
$r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($a->argv[1]),
@@ -441,10 +479,6 @@ function profiles_content(&$a) {
return;
}
- $chan = $a->get_channel();
-
- profile_load($a,$chan['channel_address'],$r[0]['id']);
-
require_once('include/profile_selectors.php');