function display($persona)
{
    $json = new Services_JSON();
    $persona->get_configuration_data();
    $properties =& PersonaProperty::load_persona_properties($persona->persona_id);
    $propertyCount = count($properties);
    // echo "<pre>" . print_r($persona, true) . "</pre>";
    if (!$propertyCount) {
        echo "No status info available";
    } else {
        foreach ($properties as $k => $property) {
            if ($property->name == 'Status') {
                $content = $json->decode($property->content);
                if ($content->friendly) {
                    echo $content->friendly;
                    echo '<br />';
                    echo 'Last fetch on: ' . date("H:i D jS M", strtotime($content->date));
                } else {
                    echo "No status info available";
                }
                /*
                echo '<!-- ' . "\n";
                echo print_r($property, true) . "\n";
                echo print_r($content, true) . "\n";
                echo ' -->';
                */
            }
        }
    }
}
function display($persona)
{
    global $service;
    $json = new Services_JSON();
    $persona->get_configuration_data();
    $service = $persona->configuration_data->service;
    $properties =& PersonaProperty::load_persona_properties($persona->persona_id);
    $propertyCount = count($properties);
    echo '<p class="header">' . $persona->name . ' (' . $service . ')</p>';
    if (!$propertyCount) {
        echo "<p>No data available</p>";
    } else {
        echo '<ul class="personaproperties" id="' . $service . '">';
        foreach ($properties as $k => $property) {
            $content = $json->decode($property->content);
            if (count($content)) {
                $viewer = $property->viewer;
                if ($service == 'Facebook' && $viewer == 'Friends') {
                    $content = reformat_facebook($content);
                    $viewer = 'FriendList';
                } else {
                    if ($service == 'Flickr' && $viewer == 'Friends') {
                        $content = reformat_flickr($content);
                        $viewer = 'FriendList';
                    } else {
                        if ($property->name == 'Status') {
                            $viewer = 'Status';
                        }
                    }
                }
                echo '<li><p class="header">' . $property->name . " (type: " . $viewer . "): </p>";
                // primitive adaptive rendering:
                if (is_callable($viewer)) {
                    // do we have a function of that name?
                    $viewer($content);
                } else {
                    pretty_print($content);
                }
                echo '</li>';
            }
        }
        echo '</ul>';
    }
}
Beispiel #3
0
function configure_persona($persona)
{
    global $base_url;
    $c = NULL;
    $c = isset($persona->configuration_data) ? $persona->configuration_data : $persona;
    echo '<div id="' . $c->service . @$c->persona_id . '" ' . 'style="display:none;">';
    echo '<input type="hidden" name="' . $c->service . '_persona_id' . '" ' . 'value="' . @$c->persona_id . '" />';
    echo '<input type="hidden" name="' . $c->service . '_persona_service_id' . '" ' . 'value="' . $c->persona_service_id . '" />';
    $submit_id = 'configure_' . $c->service;
    echo '<div class="field_big"><input type="submit" name="' . $submit_id . '" value="Save Settings" /></div>';
    if ($c->service == 'Facebook') {
        // Facebook key defined in default_config.php, can be overridden by local_config.php
        global $facebook_api_key;
        // we need to check if the Scraper has encoutered an error with the TOS
        $json = new Services_JSON();
        if (!empty($persona->persona_id)) {
            //Avoid errors if no persona_id yet
            $properties =& PersonaProperty::load_persona_properties($persona->persona_id);
            if (!empty($properties)) {
                $content = $json->decode($properties[0]->content);
            }
            if (!empty($content) && !empty($content->code)) {
                $code = $content->code;
                //Avoid error if not set
            }
        }
        if (!isset($code) || $code == 'mustagreetotos') {
            // signal for UI and
            // reset the user's checkbox
            $c->agreetotos = 'no';
        }
        if (!$c->agreetotos || $c->agreetotos == 'no') {
            $fbtos = "http://api.facebook.com/login.php?api_key={$facebook_api_key}&v=1.0";
            //v now mandatory
            $fbtostext = 'Agree to Facebook TOS';
        } else {
            $fbtos = 'http://www.facebook.com/privacy.php?view=platform&tab=ext';
            //Show all FB perms.
            $fbtostext = 'Review your Facebook permissions';
        }
        $fn = $c->service . '_agreetotos';
        echo '<div class="field_big"><h4><label for="' . $fn . '">I agree to the Facebook.com Terms of Service</label></h4>' . '<div class="center">';
        echo '<input type="checkbox" name="' . $fn . '" id="' . $fn . '" value="yes"';
        if ($c->agreetotos && $c->agreetotos == 'yes') {
            echo ' checked="checked"';
        }
        echo '/>';
        echo '</div>';
        echo '<div class="buttonbar"><ul><li>';
        echo '<a href="' . $fbtos . '" target="facebook" onclick="$(this).hide();">' . $fbtostext . '</a>';
        echo '</li></ul></div>';
        echo '</div>';
        echo '<br clear="all" />';
    }
    // end facebook code
    if ($c->service == 'Flickr') {
        // we need to check if the Scraper has encoutered an error with the TOS
        $json = new Services_JSON();
        if (!empty($persona->persona_id)) {
            //Avoid errors if no persona_id yet
            $properties =& PersonaProperty::load_persona_properties(@$persona->persona_id);
            if (!empty($properties)) {
                $content = $json->decode($properties[0]->content);
            }
            if (!empty($content)) {
                $code = $content->code;
            }
        }
        if (!isset($code) || $code == 'mustagreetotos') {
            // signal for UI and
            // reset the user's checkbox
            $c->agreetotos = 'no';
        }
        input($c->service . '_flickr_username_email', @$c->flickr_username_email, 'Your Flickr username or e-mail address', 'text');
        echo '<div class="field_big"><p>To display your public photos on your personal page,
please enter your Flickr username or e-mail address above.</p>
<p>For full Flickr integration, please also fill out the rest of this form.</p></div>';
        $fn = $c->service . '_agreetotos';
        echo '<div class="field_big"><h4><label for="' . $fn . '">I agree to the Flickr.com Terms of Service</label></h4>' . '<div class="center">';
        echo '<input type="checkbox" name="' . $fn . '" id="' . $fn . '" value="yes"';
        if ($c->agreetotos && $c->agreetotos == 'yes') {
            echo ' checked="checked"';
        }
        echo '/></div>';
        //
        if (!$c->agreetotos || $c->agreetotos == 'no') {
            $fltos = BASE_URL_REL . "/ajax/flickr_login.php";
            $fltostext = 'Agree to Flickr  TOS';
        } else {
            $fltos = 'http://www.flickr.com/services/auth/list.gne';
            $fltostext = 'Review your Flickr permissions';
        }
        echo '<div class="buttonbar"><ul><li>';
        echo '<a href="' . $fltos . '" target="flickr" onclick="$(this).hide();">' . $fltostext . '</a>';
        echo '</li></ul></div>';
        echo '</div>';
        echo '<br clear="all" />';
    }
    // end flickr code
    // the given name is always editable
    input($c->service . '_name', @$c->name, 'Your label for this account', 'text');
    // select for Persona privacy setting
    echo '<div class="field_big"><h4><label>' . 'Who may see data from this Service?</label></h4>';
    echo '<div>' . uihelper_get_user_access_list($c->service . '_perm', !empty($c->perm) ? $c->perm : NONE) . '</div>';
    //Fix case where perm not defined yet
    echo '</div>';
    if ($c->service == 'AIM' || $c->service == 'YouTube' || $c->service == 'Google') {
        // plain username
        $fieldLabel = "username";
    } else {
        if ($c->service == 'Flickr') {
            $fieldLabel = "Yahoo! ID";
        } else {
            // MySpace use email adress
            $fieldLabel = "email address";
        }
    }
    input($c->service . '_userName', @$c->userName, "Your {$fieldLabel}", 'text');
    input($c->service . '_password', @$c->password, 'Your password', 'password');
    echo '<input type="submit" name="' . $submit_id . '" value="Save Settings" />';
    echo "</div>";
}
    }
    die;
}
echo "<h2>Personas</h2>";
$personaCount = Persona::count_user_personas($user->user_id);
echo "Persona Count: " . $personaCount . "<br/>";
$personas =& Persona::load_user_personas($user->user_id);
echo "Personas: " . $personas . " count " . count($personas) . "<br/>";
echo "<hr/>";
for ($i = 0; $i < $personaCount; $i++) {
    $persona = $personas[$i];
    echo "Persona: " . $persona->persona_id . "<br/>";
    print_r($persona);
    $propertyCount = PersonaProperty::count_persona_properties($persona->persona_id);
    echo "Property count: " . $propertyCount . "<br/>";
    $properties =& PersonaProperty::load_persona_properties($persona->persona_id);
    echo "Properties: " . $properties . " count " . count($properties) . "<br/>";
    echo "<ul>";
    for ($j = 0; $j < $propertyCount; $j++) {
        $property = $properties[$j];
        echo "<li>";
        echo "Property: " . $property->persona_property_id . "<br/>";
        print_r($property);
        echo "</li>";
    }
    echo "</ul>";
    echo "<hr/>";
}
echo "<h1>Services</h1>";
$serviceCount = PersonaService::count_persona_services();
echo "Service count: " . $serviceCount . "<br/>";
 public function set_persona_property($persona_id, $name, $content = '', $content_type = 'text', $category = '', $viewer = '', $parent_id = 0)
 {
     Logger::log("Enter: function PersonaProperty::set_persona_property");
     $prop = $this->get_persona_property($persona_id, $name);
     if ($prop == null) {
         $prop = new PersonaProperty();
         $prop->persona_id = $persona_id;
         $prop->name = $name;
     }
     $prop->content = $content;
     $prop->content_type = $content_type;
     $prop->category = $category;
     $prop->viewer = $viewer;
     $prop->parent_id = $parent_id;
     $prop->serial_number++;
     $prop->last_update = time();
     $prop->content_hash = md5($content);
     $prop->save();
     Dal::commit();
     Logger::log("Exit: function PersonaProperty::set_persona_property");
 }