]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/facebookaction.php
Merge branch 'master' of /var/www/trunk
[quix0rs-gnu-social.git] / lib / facebookaction.php
index 67595861f07c3343c4a0bf7ae9811c79920c923d..6d42596e8e9a383d1eeb722e0d157481d775f27b 100644 (file)
  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('LACONICA')) {
+    exit(1);
+}
 
-require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
+require_once INSTALLDIR.'/lib/facebookutil.php';
 
-class FacebookAction extends Action {
+class FacebookAction extends Action
+{
 
-    function handle($args) {
+    function handle($args)
+    {
         parent::handle($args);
     }
 
-    function get_facebook() {
-        $apikey = common_config('facebook', 'apikey');
-        $secret = common_config('facebook', 'secret');
-        return new Facebook($apikey, $secret);
+    function showLogo(){
+
+        global $xw;
+
+        $this->showStylesheets();
+        $this->showScripts();
+
+        $this->elementStart('a', array('class' => 'url home bookmark',
+                                            'href' => common_local_url('public')));
+        if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) {
+            $this->element('img', array('class' => 'logo photo',
+                'src' => (common_config('site', 'logo')) ?
+                    common_config('site', 'logo') : theme_path('logo.png'),
+                'alt' => common_config('site', 'name')));
+        }
+
+        $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
+        $this->elementEnd('a');
+
     }
 
-    function update_profile_box($facebook, $fbuid, $user) {
+    function showHeader($msg = null, $success = false)
+    {
+        startFBML();
 
-        $notice = $user->getCurrentNotice();
+        $this->elementStart('fb:if-section-not-added', array('section' => 'profile'));
+        $this->elementStart('span', array('id' => 'add_to_profile'));
+        $this->element('fb:add-section-button', array('section' => 'profile'));
+        $this->elementEnd('span');
+        $this->elementEnd('fb:if-section-not-added');
 
-        # Need to include inline CSS for styling the Profile box
+        $this->showLogo();
 
-        $style = '<style>
-        #notices {
-        clear: both;
-        margin: 0 auto;
-        padding: 0;
-        list-style-type: none;
-        width: 600px;
-        border-top: 1px solid #dec5b5;
-        }
-        #notices a:hover {
-        text-decoration: underline;
-        }
-        .notice_single {
-        clear: both;
-        display: block;
-        margin: 0;
-        padding: 5px 5px 5px 0;
-        min-height: 48px;
-        font-family: Georgia, "Times New Roman", Times, serif;
-        font-size: 13px;
-        line-height: 16px;
-        border-bottom: 1px solid #dec5b5;
-        background-color:#FCFFF5;
-        opacity:1;
-        }
-        .notice_single:hover {
-        background-color: #f7ebcc;
-        }
-        .notice_single p {
-        display: inline;
-        margin: 0;
-        padding: 0;
+        if ($msg) {
+            if ($success) {
+                $this->element('fb:success', array('message' => $msg));
+            } else {
+                // XXX do an error message here
+            }
         }
-        </style>';
 
-        $html = $this->render_notice($notice);
+        $this->elementStart('div', 'main_body');
 
-        $fbml = "<fb:wide>$content $html</fb:wide>";
-        $fbml .= "<fb:narrow>$content $html</fb:narrow>";
+    }
 
-        $fbml_main = "<fb:narrow>$content $html</fb:narrow>";
+    function showNav($selected = 'Home')
+    {
 
-        $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
-    }
+        $this->elementStart('dl', array("id" => 'site_nav_local_views'));
+        $this->element('dt', null, _('Local Views'));
+        $this->elementStart('dd');
 
-    # Display methods
+        $this->elementStart('ul', array('class' => 'nav'));
 
-    function show_header($selected ='Home') {
+        $this->elementStart('li', array('class' =>
+            ($selected == 'Home') ? 'current' : 'facebook_home'));
+        $this->element('a',
+            array('href' => 'index.php', 'title' => _('Home')), _('Home'));
+        $this->elementEnd('li');
 
-        # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
-        $ts = filemtime(theme_file('facebookapp.css'));
-        $cssurl = theme_path('facebookapp.css') . "?ts=$ts";
+        $this->elementStart('li',
+            array('class' =>
+                ($selected == 'Invite') ? 'current' : 'facebook_invite'));
+        $this->element('a',
+            array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
+        $this->elementEnd('li');
 
-         $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
-         # $header .='<script src="" ></script>';
-          $header .= '<fb:dashboard/>';
+        $this->elementStart('li',
+            array('class' =>
+                ($selected == 'Settings') ? 'current' : 'facebook_settings'));
+        $this->element('a',
+            array('href' => 'settings.php',
+                'title' => _('Settings')), _('Settings'));
+        $this->elementEnd('li');
 
-          $header .=
-            '<fb:tabs>'
-            .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
-            .'<fb:tab-item title="Invite Friends"  href="invite.php" selected="' . ($selected == 'Invite') . '" />'
-            .'<fb:tab-item title="Settings"     href="settings.php" selected="' . ($selected == 'Settings') . '" />'
-            .'</fb:tabs>';
-          $header .= '<div id="main_body">';
+        $this->elementEnd('ul');
 
-      echo $header;
+        $this->elementEnd('dd');
+        $this->elementEnd('dl');
 
     }
 
-    function show_footer() {
-      $footer = '</div>';
-      echo $footer;
+    function showFooter()
+    {
+        $this->elementEnd('div');
+        $this->endXml();
     }
 
-    function show_login_form() {
-
-        $loginform =
-            ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
-            .'<a href="http://identi.ca/">'
-            .'    <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
-            .'</a>'
-            .'<h1 class="pagetitle">Login</h1>'
-            .'<div class="instructions">'
-            .'    <p>Login with your username and password. Don\'t have a username yet?'
-            .'      <a href="http://identi.ca/main/register">Register</a> a new account.'
-            .'    </p>'
-            .'</div>'
-            .'<div id="content">'
-            .'    <form method="post" id="login">'
-            .'      <p>'
-            .'        <label for="nickname">Nickname</label>'
-            .'        <input name="nickname" type="text" class="input_text" id="nickname"/>'
-            .'      </p>'
-            .'      <p>'
-            .'          <label for="password">Password</label>'
-            .'        <input name="password" type="password" class="password" id="password"/>'
-            .'      </p>'
-            .'      <p>'
-            .'        <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
-            .'      </p>'
-            .'    </form>'
-            .'    <p>'
-            .'      <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
-            .'    </p>'
-            .'</div';
-
-            echo $loginform;
-    }
+    function showInstructions()
+    {
+        global $xw;
 
-    function render_notice($notice) {
+        $this->elementStart('dl', array('class' => 'system_notice'));
+        $this->element('dt', null, 'Page Notice');
 
-        global $config;
+        $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
+            'with your username and password. Don\'t have a username yet? ');
 
-        $profile = $notice->getProfile();
-        $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+        $loginmsg_part2 = _(' a new account.');
 
-        $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
+        $this->elementStart('dd');
+        $this->elementStart('p');
+        $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
+        $this->element('a',
+            array('href' => common_local_url('register')), _('Register'));
+        $this->text($loginmsg_part2);
+        $this->elementEnd('dd');
+        $this->elementEnd('dl');
+    }
 
-        # XXX: we need to figure this out better. Is this right?
-        if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
-            $noticeurl = $notice->uri;
-        }
+    function showStylesheets()
+    {
+        global $xw;
 
-        $html =
-        '<li class="notice_single" id="' . $notice->id . '">'
-        .'<a href="' . $profile->profileurl . '">'
-        .'<img src="';
+        $this->element('link', array('rel' => 'stylesheet',
+                                     'type' => 'text/css',
+                                     'href' => getFacebookBaseCSS()));
 
-        if ($avatar) {
-            $html .= common_avatar_display_url($avatar);
-        } else {
-            $html .= common_default_avatar(AVATAR_STREAM_SIZE);
-        }
+        $this->element('link', array('rel' => 'stylesheet',
+                                     'type' => 'text/css',
+                                     'href' => getFacebookThemeCSS()));
+    }
 
-        $html .=
-        '" class="avatar stream" width="'
-        . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
-        .' alt="';
+    function showScripts()
+    {
+        global $xw;
 
-        if ($profile->fullname) {
-            $html .= $profile->fullname;
-        } else {
-            $html .= $profile->nickname;
-        }
+        $this->element('script', array('type' => 'text/javascript',
+                                       'src' => getFacebookJS()));
 
-        $html .=
-        '"></a>'
-        .'<a href="' .    $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
-        .'<p class="content">' . $notice->rendered . '</p>'
-        .'<p class="time">'
-        .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
+    }
 
-        if ($notice->source) {
-            $html .= _(' from ');
-            $html .= $this->source_link($notice->source);
-        }
+    function showLoginForm($msg = null)
+    {
+        startFBML();
 
-        if ($notice->reply_to) {
-            $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
-            $html .=
-            ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
-        }
+        $this->showStylesheets();
+        $this->showScripts();
 
-        $html .= '</p></li>';
+        $this->showLogo();
 
-        return $html;
-    }
+        $this->elementStart('div', array('class' => 'content'));
+        $this->element('h1', null, _('Login'));
 
-    function source_link($source) {
-        $source_name = _($source);
-
-        $html = '<span class="noticesource">';
-
-        switch ($source) {
-         case 'web':
-         case 'xmpp':
-         case 'mail':
-         case 'omb':
-         case 'api':
-            $html .= $source_name;
-            break;
-         default:
-            $ns = Notice_source::staticGet($source);
-            if ($ns) {
-                $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
-            } else {
-                $html .= $source_name;
-            }
-            break;
+        if ($msg) {
+             $this->element('fb:error', array('message' => $msg));
         }
 
-        $html .= '</span>';
-
-        return $html;
-    }
+        $this->showInstructions();
 
-    function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
+        $this->elementStart('div', array('id' => 'content_inner'));
 
-        $html = '';
+        $this->elementStart('form', array('method' => 'post',
+                                               'class' => 'form_settings',
+                                               'id' => 'login',
+                                               'action' => 'index.php'));
 
-        if ($have_before || $have_after) {
-            $html = '<div id="pagination">';
-            $html .'<ul id="nav_pagination">';
-        }
+        $this->elementStart('fieldset');
+        $this->element('legend', null, _('Login to site'));
 
-        if ($have_before) {
-            $pargs = array('page' => $page-1);
-            $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
-            $html .= '<li class="before">';
-            $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
-            $html .'</li>';
-        }
+        $this->elementStart('ul', array('class' => 'form_datas'));
+        $this->elementStart('li');
+        $this->input('nickname', _('Nickname'));
+        $this->elementEnd('li');
+        $this->elementStart('li');
+        $this->password('password', _('Password'));
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
 
-        if ($have_after) {
-            $pargs = array('page' => $page+1);
-            $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
-            $html .= '<li class="after">';
-            $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
-            $html .'</li>';
-        }
+        $this->submit('submit', _('Login'));
+        $this->elementEnd('form');
 
-        if ($have_before || $have_after) {
-            $html .= '<ul>';
-            $html .'<div>';
-        }
-    }
+        $this->elementStart('p');
+        $this->element('a', array('href' => common_local_url('recoverpassword')),
+                       _('Lost or forgotten password?'));
+        $this->elementEnd('p');
 
-    function pagination_url($fbaction, $args=NULL) {
-        global $config;
+        $this->elementEnd('div');
 
-        $extra = '';
+        $this->endXml();
 
-        if ($args) {
-            foreach ($args as $key => $value) {
-                $extra .= "&${key}=${value}";
-            }
-        }
+    }
 
-        return "$fbaction?${extra}";
+    function showNoticeForm($user)
+    {
+
+        global $xw;
+
+        $this->elementStart('form', array('id' => 'form_notice',
+                                           'method' => 'post',
+                                           'action' => 'index.php'));
+
+        $this->elementStart('fieldset');
+        $this->element('legend', null, 'Send a notice');
+
+        $this->elementStart('ul', 'form_datas');
+        $this->elementStart('li', array('id' => 'noticcommon_elemente_text'));
+        $this->element('label', array('for' => 'notice_data-text'),
+                            sprintf(_('What\'s up, %s?'), $user->nickname));
+
+        $this->element('textarea', array('id' => 'notice_data-text',
+                                              'cols' => 35,
+                                              'rows' => 4,
+                                              'name' => 'status_textarea'));
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+
+        $this->elementStart('dl', 'form_note');
+        $this->element('dt', null, _('Available characters'));
+        $this->element('dd', array('id' => 'notice_text-count'),
+                            '140');
+        $this->elementEnd('dl');
+
+        $this->elementStart('ul', array('class' => 'form_actions'));
+
+        $this->elementStart('li', array('id' => 'notice_submit'));
+
+        $this->submit('submit', _('Send'));
+
+        /*
+        $this->element('input', array('id' => 'notice_action-submit',
+                                           'class' => 'submit',
+                                           'name' => 'status_submit',
+                                           'type' => 'submit',
+                                           'value' => _('Send')));
+        */
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->elementEnd('fieldset');
+        $this->elementEnd('form');
     }
 
 }