Exemple #1
0
function pie_init()
{
    //Db::connect('users')->generateModels(PIE_DIR.DS.'plugins'.DS.'users'.DS.'classes');
    //Db::connect('games')->generateModels(PIE_DIR.DS.'plugins'.DS.'games'.DS.'classes');
    Pie::log('To stop logging database queries, change pie/init.php');
    Pie_Config::set('pie', 'handlersBeforeEvent', 'db/query/execute', 'temp_query');
}
Exemple #2
0
function users_before_pie_init()
{
    $facebook_apps = Pie_Config::get('users', 'facebookApps', array());
    foreach ($facebook_apps as $app_id => $fb_info) {
        if (isset($fb_info['url'])) {
            $subpath = isset($fb_info['subpath']) ? $fb_info['subpath'] : '';
            Pie_Config::set('pie', 'proxies', Pie_Request::baseUrl(true) . $subpath, $fb_info['url']);
        }
    }
}
Exemple #3
0
 /**
  * Pushes a new theme url  to the end of the cascade -- 
  * if a theme file doesn't exist, we go backwards through the cascade
  * and if we locate it under a previous theme url, we use that one.
  * NOTE: If your webserver supports .htaccess files, you can implement
  * cascading themes much more efficiently: simply push ONE theme url
  * using tihs function, and implement the cascade using .htaccess files.
  * @param string $theme_url
  *  The url to be prepended to all non-absolute "src" attributes 
  * (except for iframes) rendered by Pie_Html
  * @return string|null
  *  The theme url previously at the end of the cascade, if any
  */
 static function pushThemeUrl($theme_url)
 {
     $prev_theme_url = Pie_Config::get('pie', 'theme_url');
     Pie_Config::set('pie', 'theme_urls', null, $theme_url);
     Pie_Config::set('pie', 'theme_url', $theme_url);
     return $prev_theme_url;
 }
Exemple #4
0
 /**
  * Add a database connection with a name
  * @param string $name
  *  The name under which to store the connection details
  * @param array $details
  *  The connection details. Should include the keys:
  *  'dsn', 'username', 'password', 'driver_options'
  */
 static function addConnection($name, $details)
 {
     if (class_exists('Pie_Config')) {
         Pie_Config::set('db', 'connections', $name, $details);
     } else {
         // Standalone, no Pie
         self::$connections[$name] = $details;
     }
 }
Exemple #5
0
function items_addPhoto_post()
{
    if (Pie_Dispatcher::uri()->facebook) {
        return;
    }
    if (isset($_POST['fb_sig_app_id'])) {
        $app_id = $_POST['fb_sig_app_id'];
    } else {
        $app = Pie_Config::expect('pie', 'app');
        $app_id = Pie_Config::expect('users', 'facebookApps', $app, 'appId');
    }
    Users::authenticate('facebook', $app_id);
    /*
    if (!isset($_REQUEST['content'])) {
    	Pie_Response::addError(new Pie_Exception_RequiredField(array(
    		'field' => 'content'
    	)));
    	Pie_Dispatcher::showErrors();
    	return;
    }
    */
    $user = Users::loggedInUser();
    if (!$user) {
        throw new Users_Exception_NotLoggedIn();
    }
    // TODO: download a backup copy into a special place for facebook photos
    // TODO: handle uploads
    // Facebook photo
    if (!empty($_POST['src_big'])) {
        if (!is_array($_POST['src_big'])) {
            throw new Exception("src_big must be an array");
        }
        // First, we download the photo to store on our site
        foreach ($_POST['src_big'] as $pid => $src_big) {
            $src_small = Pie::ifset($_POST['src_small'][$pid], $src_big);
            $parts = explode('/', $src_big);
            $parts = explode('.', end($parts));
            $ext = end($parts);
            $filename = 'photos' . DS . 'facebook' . DS . "pid{$pid}.{$ext}";
            $abs_filename = ITEMS_PLUGIN_FILES_DIR . DS . $filename;
            if (file_exists($abs_filename)) {
                // A photo was already copied to this filename
                Pie_Config::set('items', 'addPhoto', 'result', 'exists');
                $photo = new Items_Photo();
                $photo->filename = $filename;
                if ($photo = $photo->retrieve()) {
                    $item = new Items_Item();
                    $item->id = $photo->item_id;
                    $item = $item->retrieve();
                    // relies on DB consistency
                    Pie_Config::set('items', 'addPhoto', 'item_id', $item->id);
                    Pie_Config::set('items', 'addPhoto', 'state', $item->state);
                }
                return;
            }
            copy($src_big, $abs_filename);
            $item = new Items_Item();
            $item->by_user_id = $user->id;
            $item->thumb_url = $src_small;
            $item->share_count = 0;
            $item->state = 'pending';
            Pie::event('items/addPhoto/saveItem', compact('item'), 'before');
            $item->save();
            $photo = new Items_Photo();
            $photo->src_url = $src_big;
            $photo->filename = $filename;
            $photo->item_id = $item->id;
            Pie::event('items/addPhoto/savePhoto', compact('photo'), 'before');
            $photo->save();
        }
    } else {
        if (isset($_FILES['upload'])) {
            // TODO: maybe add checks for size, mime type, etc.
            if ($errcode = $_FILES['upload']['error']) {
                $code = $_FILES['upload']['error'];
                throw new Pie_Exception_UploadError(compact('code'));
            }
            $parts = explode('.', $_FILES['upload']['name']);
            $ext = end($parts);
            $uniqid = isset($_POST['uniqid']) ? $_POST['uniqid'] : uniqid('up.', false);
            $md5 = md5($_FILES['upload']['name']);
            $dirname = 'photos' . DS . 'user' . $user->id;
            $abs_dirname = ITEMS_PLUGIN_FILES_DIR . DS . $dirname;
            if (!file_exists($abs_dirname)) {
                mkdir($abs_dirname, 0777, true);
            }
            $filename = $dirname . DS . "{$uniqid}.{$md5}.{$ext}";
            $abs_filename = ITEMS_PLUGIN_FILES_DIR . DS . $filename;
            if (file_exists($abs_filename)) {
                // A file was already uploaded via this uniqid
                Pie_Config::set('items', 'addPhoto', 'result', 'exists');
                $photo = new Items_Photo();
                $photo->filename = $filename;
                if ($photo = $photo->retrieve()) {
                    $item = new Items_Item();
                    $item->id = $photo->item_id;
                    $item = $item->retrieve();
                    // relies on DB consistency
                    Pie_Config::set('items', 'addPhoto', 'item_id', $item->id);
                    Pie_Config::set('items', 'addPhoto', 'state', $item->state);
                }
                return;
            }
            move_uploaded_file($_FILES['upload']['tmp_name'], $abs_filename);
            $src_big = 'plugins/items/photos/user' . $user->id . "/{$uniqid}.{$md5}.{$ext}";
            $src_small = $src_big;
            // TODO: make small version!!!! AND PUT INTO thumb_url
            // Try different functions if they exist, from graphics libs
            $item = new Items_Item();
            $item->by_user_id = $user->id;
            $item->thumb_url = $src_small;
            $item->share_count = 0;
            $item->state = 'pending';
            Pie::event('items/addPhoto/saveItem', compact('item'), 'before');
            $item->save();
            $photo = new Items_Photo();
            $photo->src_url = $src_big;
            $photo->filename = $filename;
            $photo->item_id = $item->id;
            Pie::event('items/addPhoto/savePhoto', compact('photo'), 'before');
            $photo->save();
        }
    }
    // Report as added
    if (!empty($item)) {
        Pie_Config::set('items', 'addPhoto', 'result', 'added');
        Pie_Config::set('items', 'addPhoto', 'item_id', $item->id);
        Pie_Config::set('items', 'addPhoto', 'state', $item->state);
    }
}
Exemple #6
0
 /**
  * Adds the first alias to the configuration
  */
 static function addAlias()
 {
     Pie_Config::set('pie', 'aliases', '', APP_WEB_DIR);
 }