never use profile_load outside of a module's _init() function

This commit is contained in:
Zach Prezkuta 2013-01-03 10:47:45 -07:00
parent 405f37b7ae
commit fdd142c42e
24 changed files with 214 additions and 164 deletions

View File

@ -1107,6 +1107,10 @@ if(! function_exists('get_max_import_size')) {
* Profile information is placed in the App structure for later retrieval. * Profile information is placed in the App structure for later retrieval.
* Honours the owner's chosen theme for display. * Honours the owner's chosen theme for display.
* *
* IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
* the theme is chosen before the _init() function of a theme is run, which will usually
* load a lot of theme-specific content
*
*/ */
if(! function_exists('profile_load')) { if(! function_exists('profile_load')) {
@ -1185,6 +1189,8 @@ if(! function_exists('profile_load')) {
* load/reload current theme info * load/reload current theme info
*/ */
set_template_engine($a); // reset the template engine to the default in case the user's theme doesn't specify one
$theme_info_file = "view/theme/".current_theme()."/theme.php"; $theme_info_file = "view/theme/".current_theme()."/theme.php";
if (file_exists($theme_info_file)){ if (file_exists($theme_info_file)){
require_once($theme_info_file); require_once($theme_info_file);

View File

@ -1,13 +1,22 @@
<?php <?php
function display_content(&$a, $update = 0) { function display_init(&$a) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL); notice( t('Public access denied.') . EOL);
killme();
return; return;
} }
$nick = (($a->argc > 1) ? $a->argv[1] : '');
profile_load($a,$nick);
}
function display_content(&$a, $update = 0) {
require_once("include/bbcode.php"); require_once("include/bbcode.php");
require_once('include/security.php'); require_once('include/security.php');
require_once('include/conversation.php'); require_once('include/conversation.php');
@ -25,7 +34,6 @@ function display_content(&$a, $update = 0) {
else { else {
$nick = (($a->argc > 1) ? $a->argv[1] : ''); $nick = (($a->argc > 1) ? $a->argv[1] : '');
} }
profile_load($a,$nick);
if($update) { if($update) {
$item_id = $_REQUEST['item_id']; $item_id = $_REQUEST['item_id'];

View File

@ -33,7 +33,6 @@ function profile_init(&$a) {
auto_redir($a, $which); auto_redir($a, $which);
} }
set_template_engine($a); // reset the template engine to the default in case the user's theme doesn't specify one
profile_load($a,$which,$profile); profile_load($a,$which,$profile);
$blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);

View File

@ -1,6 +1,147 @@
<?php <?php
function profiles_init(&$a) {
nav_set_selected('profiles');
if(! local_user()) {
notice( t('Permission denied.') . EOL);
killme();
return;
}
if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->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
}
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 `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
intval(local_user()),
intval($a->argv[2]),
intval(local_user())
);
$r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($a->argv[2]),
intval(local_user())
);
if($r)
info( t('Profile deleted.') . EOL);
goaway($a->get_baseurl(true) . '/profiles');
return; // NOTREACHED
}
if(($a->argc > 1) && ($a->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` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
VALUES ( %d, '%s', '%s', '%s', '%s' )",
intval(local_user()),
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(($a->argc > 2) && ($a->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);
killme();
return;
}
unset($r1[0]['id']);
$r1[0]['is-default'] = 0;
$r1[0]['publish'] = 0;
$r1[0]['net-publish'] = 0;
$r1[0]['profile-name'] = dbesc($name);
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(($a->argc > 1) && (intval($a->argv[1]))) {
$r = q("SELECT id 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);
killme();
return;
}
profile_load($a,$a->user['nickname'],$r[0]['id']);
}
}
function profiles_post(&$a) { function profiles_post(&$a) {
if(! local_user()) { if(! local_user()) {
@ -425,126 +566,6 @@ function profile_activity($changed, $value) {
function profiles_content(&$a) { function profiles_content(&$a) {
$o = ''; $o = '';
nav_set_selected('profiles');
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->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
}
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 `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
intval(local_user()),
intval($a->argv[2]),
intval(local_user())
);
$r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($a->argv[2]),
intval(local_user())
);
if($r)
info( t('Profile deleted.') . EOL);
goaway($a->get_baseurl(true) . '/profiles');
return; // NOTREACHED
}
if(($a->argc > 1) && ($a->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` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
VALUES ( %d, '%s', '%s', '%s', '%s' )",
intval(local_user()),
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(($a->argc > 2) && ($a->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]['net-publish'] = 0;
$r1[0]['profile-name'] = dbesc($name);
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(($a->argc > 1) && (intval($a->argv[1]))) { if(($a->argc > 1) && (intval($a->argv[1]))) {
$r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@ -556,8 +577,6 @@ function profiles_content(&$a) {
return; return;
} }
profile_load($a,$a->user['nickname'],$r[0]['id']);
require_once('include/profile_selectors.php'); require_once('include/profile_selectors.php');

View File

@ -5,12 +5,13 @@
* Version: * Version:
* Author: Christian Vogeley (https://christian-vogeley.de/profile/christian) * Author: Christian Vogeley (https://christian-vogeley.de/profile/christian)
*/ */
function cleanzero_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function cleanzero_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>

View File

@ -8,6 +8,7 @@
*/ */
function comix_plain_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
@ -59,3 +60,5 @@ $('.savedsearchterm').hover(
</script> </script>
EOT; EOT;
}

View File

@ -8,6 +8,7 @@
*/ */
function comix_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
@ -59,3 +60,5 @@ $('.savedsearchterm').hover(
</script> </script>
EOT; EOT;
}

View File

@ -7,6 +7,7 @@
*/ */
function darkbubble_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'testbubble', 'extends' => 'testbubble',
); );
@ -21,3 +22,4 @@ $('html').click(function() { $("#nav-notifications-menu" ).hide(); });
}); });
</script> </script>
EOT; EOT;
}

View File

@ -7,11 +7,11 @@
* Author: Mike Macgirvin <mike@macgirvin.com> * Author: Mike Macgirvin <mike@macgirvin.com>
*/ */
function darkzero_NS_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
function darkzero_NS_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {
@ -94,4 +94,4 @@ $('.savedsearchterm').hover(
</script> </script>
EOT; EOT;
} }

View File

@ -8,12 +8,12 @@
* Maintainer: Mike Macgirvin <mike@macgirvin.com> * Maintainer: Mike Macgirvin <mike@macgirvin.com>
*/ */
function darkzero_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function darkzero_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {

View File

@ -7,9 +7,6 @@
* Author: * Author:
*/ */
$a = get_app();
set_template_engine($a, 'smarty3');
function get_diabook_config($key, $default = false) { function get_diabook_config($key, $default = false) {
if (local_user()) { if (local_user()) {
$result = get_pconfig(local_user(), "diabook", $key); $result = get_pconfig(local_user(), "diabook", $key);
@ -26,6 +23,8 @@ function get_diabook_config($key, $default = false) {
function diabook_init(&$a) { function diabook_init(&$a) {
set_template_engine($a, 'smarty3');
//print diabook-version for debugging //print diabook-version for debugging
$diabook_version = "Diabook (Version: 1.027)"; $diabook_version = "Diabook (Version: 1.027)";
$a->page['htmlhead'] .= sprintf('<META NAME=generator CONTENT="%s"/>', $diabook_version); $a->page['htmlhead'] .= sprintf('<META NAME=generator CONTENT="%s"/>', $diabook_version);

View File

@ -8,14 +8,13 @@
* Screenshot: <a href="screenshot.jpg">Screenshot</a> * Screenshot: <a href="screenshot.jpg">Screenshot</a>
*/ */
$a = get_app();
$a->theme_info = array(
'family' => 'dispy',
'name' => 'dark',
);
set_template_engine($a, 'smarty3');
function dispy_dark_init(&$a) { function dispy_dark_init(&$a) {
$a->theme_info = array(
'family' => 'dispy',
'name' => 'dark',
);
set_template_engine($a, 'smarty3');
/** @purpose set some theme defaults /** @purpose set some theme defaults
*/ */
$cssFile = null; $cssFile = null;

View File

@ -8,15 +8,14 @@
* Screenshot: <a href="screenshot.jpg">Screenshot</a> * Screenshot: <a href="screenshot.jpg">Screenshot</a>
*/ */
$a = get_app();
$a->theme_info = array(
'family' => 'dispy',
'name' => 'light',
);
set_template_engine($a, 'smarty3');
function dispy_light_init(&$a) { function dispy_light_init(&$a) {
$a->theme_info = array(
'family' => 'dispy',
'name' => 'light',
);
set_template_engine($a, 'smarty3');
/** @purpose set some theme defaults /** @purpose set some theme defaults
*/ */
$cssFile = null; $cssFile = null;

View File

@ -17,15 +17,14 @@
* or rename to prefix1_function_name (prefix2_function_name), etc. * or rename to prefix1_function_name (prefix2_function_name), etc.
*/ */
$a = get_app();
$a->theme_info = array(
'family' => 'dispy',
'version' => '1.2.2'
);
set_template_engine($a, 'smarty3');
function dispy_init(&$a) { function dispy_init(&$a) {
$a->theme_info = array(
'family' => 'dispy',
'version' => '1.2.2'
);
set_template_engine($a, 'smarty3');
/** @purpose set some theme defaults /** @purpose set some theme defaults
*/ */
$cssFile = null; $cssFile = null;

View File

@ -1,4 +1,7 @@
<?php <?php
function easterbunny_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
}

View File

@ -1,4 +1,6 @@
<?php <?php
function facepark_init(&$a) {
$a->theme_info = array(); $a->theme_info = array();
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
@ -48,3 +50,5 @@ $('.savedsearchterm').hover(
</script> </script>
EOT; EOT;
}

View File

@ -1,10 +1,11 @@
<?php <?php
function greenzero_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function greenzero_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {

View File

@ -1,10 +1,11 @@
<?php <?php
function purplezero_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function purplezero_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {

View File

@ -7,10 +7,10 @@
* Maintainer: Tobias <https://diekershoff.homeunix.net/friendica/profile/tobias> * Maintainer: Tobias <https://diekershoff.homeunix.net/friendica/profile/tobias>
*/ */
function quattro_init(&$a) {
$a->theme_info = array(); $a->theme_info = array();
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function quattro_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {

View File

@ -1,9 +1,10 @@
<?php <?php
function slack_NS_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
function slack_NS_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {
@ -86,4 +87,4 @@ $('.savedsearchterm').hover(
</script> </script>
EOT; EOT;
} }

View File

@ -1,10 +1,11 @@
<?php <?php
function slackr_init(&$a) {
$a->theme_info = array( $a->theme_info = array(
'extends' => 'duepuntozero', 'extends' => 'duepuntozero',
); );
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
function slackr_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {

View File

@ -9,11 +9,10 @@
* Screenshot: <a href="screenshot.png">Screenshot</a> * Screenshot: <a href="screenshot.png">Screenshot</a>
*/ */
$a = get_app();
$a->theme_info = array();
set_template_engine($a, 'smarty3');
function smoothly_init(&$a) { function smoothly_init(&$a) {
$a->theme_info = array();
set_template_engine($a, 'smarty3');
$cssFile = null; $cssFile = null;
$ssl_state = null; $ssl_state = null;
$baseurl = $a->get_baseurl($ssl_state); $baseurl = $a->get_baseurl($ssl_state);

View File

@ -8,6 +8,8 @@
* Maintainer: Mike Macgirvin <mike@macgirvin.com> * Maintainer: Mike Macgirvin <mike@macgirvin.com>
*/ */
function testbubble_init(&$a) {
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
@ -18,3 +20,4 @@ $('html').click(function() { $("#nav-notifications-menu" ).hide(); });
}); });
</script> </script>
EOT; EOT;
}

View File

@ -8,11 +8,11 @@
* Description: "Vier" uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/ * Description: "Vier" uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
*/ */
function vier_init(&$a) {
set_template_engine($a, 'smarty3'); set_template_engine($a, 'smarty3');
$a->theme_info = array(); $a->theme_info = array();
function vier_init(&$a) {
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script> <script>
function insertFormatting(comment,BBcode,id) { function insertFormatting(comment,BBcode,id) {