]> git.mxchange.org Git - friendica.git/blobdiff - mod/directory.php
Merge pull request #3965 from tobiasd/20171126-docGettingStarted
[friendica.git] / mod / directory.php
index b0f1cb716ba612ef53daa295ce3e5f04e87c1763..4ce919b08bd40ae46ff8e5dd7143ab0fc70f706b 100644 (file)
@@ -1,6 +1,11 @@
 <?php
 
-function directory_init(&$a) {
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Object\Contact;
+
+function directory_init(App $a) {
        $a->set_pager_itemspage(60);
 
        if(local_user()) {
@@ -9,31 +14,23 @@ function directory_init(&$a) {
                $a->page['aside'] .= findpeople_widget();
 
                $a->page['aside'] .= follow_widget();
-
        }
        else {
                unset($_SESSION['theme']);
                unset($_SESSION['mobile-theme']);
        }
-
-
 }
 
-
-function directory_post(&$a) {
+function directory_post(App $a) {
        if(x($_POST,'search'))
                $a->data['search'] = $_POST['search'];
 }
 
-
-
-function directory_content(&$a) {
-       global $db;
-
+function directory_content(App $a) {
        require_once("mod/proxy.php");
 
-       if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || 
-               (get_config('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
+       if((Config::get('system','block_public')) && (! local_user()) && (! remote_user()) ||
+               (Config::get('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
                notice( t('Public access denied.') . EOL);
                return;
        }
@@ -47,7 +44,7 @@ function directory_content(&$a) {
                $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
 
        $gdirpath = '';
-       $dirurl = get_config('system','directory');
+       $dirurl = Config::get('system','directory');
        if(strlen($dirurl)) {
                $gdirpath = zrl($dirurl,true);
        }
@@ -57,57 +54,55 @@ function directory_content(&$a) {
 
                $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
                                (`user`.`nickname` LIKE '%$search%') OR
-                               (`pdesc` LIKE '%$search%') OR
-                               (`locality` LIKE '%$search%') OR
-                               (`region` LIKE '%$search%') OR
-                               (`country-name` LIKE '%$search%') OR
-                               (`gender` LIKE '%$search%') OR
-                               (`marital` LIKE '%$search%') OR
-                               (`sexual` LIKE '%$search%') OR
-                               (`about` LIKE '%$search%') OR
-                               (`romance` LIKE '%$search%') OR
-                               (`work` LIKE '%$search%') OR
-                               (`education` LIKE '%$search%') OR
-                               (`pub_keywords` LIKE '%$search%') OR
-                               (`prv_keywords` LIKE '%$search%'))";
+                               (`profile`.`pdesc` LIKE '%$search%') OR
+                               (`profile`.`locality` LIKE '%$search%') OR
+                               (`profile`.`region` LIKE '%$search%') OR
+                               (`profile`.`country-name` LIKE '%$search%') OR
+                               (`profile`.`gender` LIKE '%$search%') OR
+                               (`profile`.`marital` LIKE '%$search%') OR
+                               (`profile`.`sexual` LIKE '%$search%') OR
+                               (`profile`.`about` LIKE '%$search%') OR
+                               (`profile`.`romance` LIKE '%$search%') OR
+                               (`profile`.`work` LIKE '%$search%') OR
+                               (`profile`.`education` LIKE '%$search%') OR
+                               (`profile`.`pub_keywords` LIKE '%$search%') OR
+                               (`profile`.`prv_keywords` LIKE '%$search%'))";
        }
 
-       $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
+       $publish = ((Config::get('system','publish_all')) ? '' : " AND `publish` = 1 " );
 
 
-       $r = $db->q("SELECT COUNT(*) AS `total` FROM `profile`
+       $r = q("SELECT COUNT(*) AS `total` FROM `profile`
                        LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
                        WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
-       if(count($r))
+       if (DBM::is_result($r))
                $a->set_pager_total($r[0]['total']);
 
        $order = " ORDER BY `name` ASC ";
 
        $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
 
-       $r = $db->q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags` FROM `profile`
+       $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
+                       `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
                        LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                       WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT ".$limit);
-       if(count($r)) {
+                       LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
+                       WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
+       if (DBM::is_result($r)) {
 
-               if(in_array('small', $a->argv))
+               if (in_array('small', $a->argv)) {
                        $photo = 'thumb';
-               else
+               }
+               else {
                        $photo = 'photo';
+               }
 
-               foreach($r as $rr) {
-
-                       $community = '';
+               foreach ($r as $rr) {
 
-                       // get the friendica address and the profile url of the user
-                       $p = q("SELECT `addr` AS faddr, `url` AS profile_url FROM `contact` WHERE `uid` = %d AND `self`",
-                               intval($rr['uid'])
-                       );
+                       $itemurl= '';
 
-                       if(count($p))
-                               $itemurl = (($p['0']['faddr'] != "") ? $p['0']['faddr'] : $p['0']['profile_url']);
+                       $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
 
-                       $profile_link = z_root() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
+                       $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
 
                        $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
 
@@ -126,18 +121,11 @@ function directory_content(&$a) {
                        }
 //                     if(strlen($rr['dob'])) {
 //                             if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
-//                                     $details .= '<br />' . t('Age: ') . $years ; 
+//                                     $details .= '<br />' . t('Age: ') . $years ;
 //                     }
 //                     if(strlen($rr['gender']))
 //                             $details .= '<br />' . t('Gender: ') . $rr['gender'];
 
-
-                       // show if account is a community account
-                       // ToDo the other should be also respected, but first we need a good translatiion
-                       // and systemwide consistency for displaying the page type
-                       if(intval($rr['page-flags']) == PAGE_COMMUNITY OR intval($rr['page-flags']) == PAGE_PRVGROUP)
-                               $community = true;
-
                        $profile = $rr;
 
                        if((x($profile,'address') == 1)
@@ -161,18 +149,20 @@ function directory_content(&$a) {
                        else {
                                $location_e = $location;
                        }
-                       
-                       $photo_menu = array(array(t("View Profile"), zrl($profile_link)));
+
+                       $photo_menu = array(
+                               'profile' => array(t("View Profile"), zrl($profile_link))
+                       );
 
                        $entry = array(
                                'id' => $rr['id'],
                                'url' => $profile_link,
                                'itemurl' => $itemurl,
-                               'thumb' => proxy_url($a->get_cached_avatar_image($rr[$photo]), false, PROXY_SIZE_THUMB),
+                               'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
                                'img_hover' => $rr['name'],
                                'name' => $rr['name'],
                                'details' => $details,
-                               'account_type' => ($community ? t('Forum') : ''),
+                               'account_type' => Contact::getAccountType($rr),
                                'profile' => $profile,
                                'location' => $location_e,
                                'tags' => $rr['pub_keywords'],
@@ -207,7 +197,7 @@ function directory_content(&$a) {
                        '$gdirpath' => $gdirpath,
                        '$desc' => t('Find on this site'),
                        '$contacts' => $entries,
-                       '$finding' => t('Finding:'),
+                       '$finding' => t('Results for:'),
                        '$findterm' => (strlen($search) ? $search : ""),
                        '$title' => t('Site Directory'),
                        '$submit' => t('Find'),