]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/common.php
fixup argument handling in action superclass
[quix0rs-gnu-social.git] / lib / common.php
index 973b1c6e6c59cea6b75f6dba9a916d0745cc95a5..5eed1bb81b3025331b5d738b4f3339f6c29e4609 100644 (file)
@@ -1,26 +1,62 @@
 <?php
+/* 
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
 
-if (!defined('MICROBLOG')) { exit(1) }
+/* XXX: break up into separate modules (HTTP, HTML, user, files) */
+
+
+if (!defined('LACONICA')) { exit(1); }
+
+define('AVATAR_PROFILE_SIZE', 96);
+define('AVATAR_STREAM_SIZE', 48);
+define('AVATAR_MINI_SIZE', 24);
+define('MAX_AVATAR_SIZE', 256 * 1024);
 
 # global configuration object
 
+require_once('PEAR.php');
+require_once('DB/DataObject.php');
+
 // default configuration, overwritten in config.php
 
 $config =
   array('site' =>
-               array('name' => 'Just another µB'),
-               'dsn' =>
-               array('phptype' => 'mysql',
-                         'username' => 'stoica',
-                         'password' => 'apasswd',
-                         'hostspec' => 'localhost',
-                         'database' => 'thedb')
-               'dboptions' =>
-               array('debug' => 2,
-                         'portability' => DB_PORTABILITY_ALL));
-
-require_once(INSTALLDIR . '/config.php');
-require_once('DB.php');
+               array('name' => 'Just another Laconica microblog',
+                         'server' => 'localhost',
+                         'path' => '/'),
+               'avatar' =>
+               array('directory' => INSTALLDIR . 'files',
+                         'path' => '/files')
+);
+
+$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
+
+$config['db'] = 
+  array('database' => 'YOU HAVE TO SET THIS IN config.php',
+           'schema_location' => $INSTALLDIR . '/classes',
+               'class_location' => $INSTALLDIR . '/classes',
+               'require_prefix' => 'classes/',
+               'class_prefix' => '',
+        'db_driver' => 'MDB2',
+               'quote_identifiers' => false);
+
+require_once(INSTALLDIR.'/config.php');
+require_once(INSTALLDIR.'/lib/action.php');
 
 # Show a server error
 
@@ -91,7 +127,7 @@ function common_head_menu() {
                common_menu_item(common_local_url('showstream', array('nickname' =>
                                                                                                                          $user->nickname)),
                                                 _t('Profile'),  $user->fullname || $user->nickname);
-               common_menu_item(common_local_url('settings'),
+               common_menu_item(common_local_url('profilesettings'),
                                                 _t('Settings'));
                common_menu_item(common_local_url('logout'),
                                                 _t('Logout'));
@@ -124,6 +160,13 @@ function common_menu_item($url, $text, $title=NULL) {
        common_element_end('li');
 }
 
+function common_input($id, $label) {
+       common_element('label', array('for' => $id), $label);
+       common_element('input', array('name' => $id,
+                                                                 'type' => 'text',
+                                                                 'id' => $id));
+}
+
 # salted, hashed passwords are stored in the DB
 
 function common_munge_password($id, $password) {
@@ -200,6 +243,67 @@ function common_render_content($text) {
        return htmlspecialchars($text);
 }
 
+// where should the avatar go for this user?
+
+function common_avatar_filename($user, $extension, $size=NULL) {
+       global $config;
+
+       if ($size) {
+               return $user->id . '-' . $size . $extension;
+       } else {
+               return $user->id . '-original' . $extension;
+       }
+}
+
+function common_avatar_path($filename) {
+       global $config;
+       return $config['avatar']['directory'] . '/' . $filename;
+}
+
+function common_avatar_url($filename) {
+       global $config;
+       return $config['avatar']['path'] . '/' . $filename;
+}
+
+function common_local_url($action, $args=NULL) {
+       global $config;
+       /* XXX: pretty URLs */
+       $extra = '';
+       if ($args) {
+               foreach ($args as $key => $value) {
+                       $extra .= "&${key}=${value}";
+               }
+       }
+       $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : '';
+       return "http://".$config['site']['server'].'/'.$pathpart."index.php?action=${action}${extra}";
+}
+
+function commmon_date_string($dt) {
+       // XXX: do some sexy date formatting
+       return date(DATE_RFC822);
+}
+
+function common_redirect($url, $code=307) {
+       static $status = array(301 => "Moved Permanently",
+                                                  302 => "Found",
+                                                  303 => "See Other",
+                                                  307 => "Temporary Redirect");
+       header("Status: ${code} $status[$code]");
+       header("Location: $url");
+       common_element('a', array('href' => $url), $url);
+}
+
+function common_broadcast_notices($id) {
+       // XXX: broadcast notices to remote subscribers
+       // XXX: broadcast notices to SMS
+       // XXX: broadcast notices to Jabber
+       // XXX: broadcast notices to other IM
+       // XXX: use a queue system like http://code.google.com/p/microapps/wiki/NQDQ
+       return true;
+}
+
 // XXX: set up gettext
 
-function _t($str) { $str }
+function _t($str) { 
+       return $str;
+}