+
+
+/**
+ *
+ * Function: profile_sidebar
+ *
+ * Formats a profile for display in the sidebar.
+ * It is very difficult to templatise the HTML completely
+ * because of all the conditional logic.
+ *
+ * @parameter: array $profile
+ *
+ * Returns HTML string stuitable for sidebar inclusion
+ * Exceptions: Returns empty string if passed $profile is wrong type or not populated
+ *
+ */
+
+
+if(! function_exists('profile_sidebar')) {
+function profile_sidebar($profile) {
+
+ $o = '';
+ $location = '';
+ $address = false;
+
+ if((! is_array($profile)) && (! count($profile)))
+ return $o;
+
+ $fullname = '<div class="fn">' . $profile['name'] . '</div>';
+
+ $tabs = '';
+
+ $photo = '<div id="profile=photo-wrapper"><img class="photo" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
+
+ $connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : '');
+
+ if((x($profile,'address') == 1)
+ || (x($profile,'locality') == 1)
+ || (x($profile,'region') == 1)
+ || (x($profile,'postal-code') == 1)
+ || (x($profile,'country-name') == 1))
+ $address = true;
+
+ if($address) {
+ $location .= '<div class="location"><span class="location-label">' . t('Location:') . '</span> <div class="adr">';
+ $location .= ((x($profile,'address') == 1) ? '<div class="street-address">' . $profile['address'] . '</div>' : '');
+ $location .= (((x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1))
+ ? '<span class="city-state-zip"><span class="locality">' . $profile['locality'] . '</span>'
+ . ((x($profile['locality']) == 1) ? t(', ') : '')
+ . '<span class="region">' . $profile['region'] . '</span>'
+ . ' <span class="postal-code">' . $profile['postal-code'] . '</span></span>' : '');
+ $location .= ((x($profile,'country-name') == 1) ? ' <span class="country-name">' . $profile['country-name'] . '</span>' : '');
+ $location .= '</div></div><div class="profile-clear"></div>';
+
+ }
+
+ $gender = ((x($profile,'gender') == 1) ? '<div class="mf"><span class="gender-label">' . t('Gender:') . '</span> <span class="x-gender">' . $profile['gender'] . '</span></div><div class="profile-clear"></div>' : '');
+
+ $pubkey = ((x($profile,'pubkey') == 1) ? '<div class="key" style="display:none;">' . $profile['pubkey'] . '</div>' : '');
+
+ $marital = ((x($profile,'marital') == 1) ? '<div class="marital"><span class="marital-label"><span class="heart">♥</span> ' . t('Status:') . ' </span><span class="marital-text">' . $profile['marital'] . '</span></div></div><div class="profile-clear"></div>' : '');
+
+ $homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div></div><div class="profile-clear"></div>' : '');
+
+ $tpl = load_view_file('view/profile_vcard.tpl');
+
+ $o .= replace_macros($tpl, array(
+ '$fullname' => $fullname,
+ '$tabs' => $tabs,
+ '$photo' => $photo,
+ '$connect' => $connect,
+ '$location' => $location,
+ '$gender' => $gender,
+ '$pubkey' => $pubkey,
+ '$marital' => $marital,
+ '$homepage' => $homepage
+ ));
+
+ call_hooks('profile_sidebar', $o);
+
+ return $o;
+}}
+
+
+if(! function_exists('register_hook')) {
+function register_hook($hook,$file,$function) {
+
+ $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
+ dbesc($hook),
+ dbesc($file),
+ dbesc($function)
+ );
+ if(count($r))
+ return true;
+
+ $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
+ dbesc($hook),
+ dbesc($file),
+ dbesc($function)
+ );
+ return $r;
+}}
+
+if(! function_exists('unregister_hook')) {
+function unregister_hook($hook,$file,$function) {
+
+ $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
+ dbesc($hook),
+ dbesc($file),
+ dbesc($function)
+ );
+ return $r;
+}}
+
+
+if(! function_exists('load_hooks')) {
+function load_hooks() {
+ $a = get_app();
+ $r = q("SELECT * FROM `hook` WHERE 1");
+ if(count($r)) {
+ foreach($r as $rr) {
+ $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
+ }
+ }
+}}
+
+
+if(! function_exists('call_hooks')) {
+function call_hooks($name, &$data = null) {
+ $a = get_app();
+
+ if(count($a->hooks)) {
+ foreach($a->hooks as $hook) {
+ if($hook[HOOK_HOOK] === $name) {
+ @include_once($hook[HOOK_FILE]);
+ if(function_exists($hook[HOOK_FUNCTION])) {
+ $func = $hook[HOOK_FUNCTION];
+ $func($a,$data);
+ }
+ }
+ }
+ }
+}}
+