/** * @return Graph|Doctrine_Record */ protected function saveGraph() { $graph = new Graph(); $graph->decision_id = $this->decision_id; $graph->graph_type_id = $this->graph_type_id; $graph->save(); return $graph; }
/** * Save the data in to database (graph_changes table) */ public function saveData() { $graph = GraphTable::getInstance()->createQuery('g')->select('g.id')->where('g.decision_id = ?', $this->decision_id)->andWhere('g.graph_type_id IS NULL')->limit(1)->fetchArray(); // try update changes if (count($graph)) { $graphChanges = Doctrine_Query::create()->select('gd.id, gd.criterion_id, gd.number, c.name AS name')->from('GraphChanges gd')->leftJoin('gd.Criterion c')->where('gd.graph_id = ?', $graph[0]['id'])->execute(); foreach ($this->collection as $item) { $updated = false; // update foreach ($graphChanges as $graphChange) { if ($item['id'] == $graphChange->criterion_id) { $graphChange->number = $item['value']; $graphChange->save(); $updated = true; } } // insert if (!$updated) { $gc = new GraphChanges(); $gc->graph_id = $graph[0]['id']; $gc->criterion_id = $item['id']; $gc->number = $item['value']; $gc->save(); } } // or create new changes } else { $graph = new Graph(); $graph->decision_id = $this->decision_id; $graph->save(); foreach ($this->collection as $item) { // insert $gc = new GraphChanges(); $gc->graph_id = $graph->id; $gc->criterion_id = $item['id']; $gc->number = $item['value']; $gc->save(); } } }
static function create_twitter_account($redirect_url) { $response = array('status' => false); if (isset($_SESSION['login'])) { unset($_SESSION['login']); } require_once ABSPATH . "/includes/plugins/twitter/twitteroauth.php"; $tokens = $_SESSION['tokens']; $twitter_config = get_config('twitter'); if ($tokens === null) { $connection = new TwitterOAuth($twitter_config['key'], $twitter_config['secret']); $request_token = $connection->getRequestToken($redirect_url); $_SESSION['tokens'] = array('oauth_token' => $request_token['oauth_token'], 'oauth_token_secret' => $request_token['oauth_token_secret']); switch ($connection->http_code) { case 200: $url = $connection->getAuthorizeURL($request_token['oauth_token']); $response = array('status' => 'redirect', 'url' => $url); return $response; break; default: $response = array('status' => 'error', 'message' => 'Could not connect to Twitter. Refresh the page or try again later.'); return $response; break; } } else { $connection = new TwitterOAuth($twitter_config['key'], $twitter_config['secret'], $tokens['oauth_token'], $tokens['oauth_token_secret']); $oauth_verifier = $connection->getAccessToken($_REQUEST['oauth_verifier']); // Let's get the user's info $user_info = $connection->get('account/verify_credentials'); $followers = $user_info->followers_count; // Print user's info if (isset($user_info->error) || isset($user_info->errors)) { // Something's wrong, go back to square 1 $response = array('status' => 'redirect_error', 'url' => base_url('login'), 'message' => $user_info->error); return $response; } else { $user = Users_Model::find_by_email($user_info->id); if (sizeof($user) <= 0) { $user = new Users_Model(); } $user->first_name = $user_info->screen_name; $user->last_name = $user_info->screen_name; $user->email = $user_info->id; $user->type = self::USER_TYPE_TWITTER; $user->twitter_oauth_token = $oauth_verifier['oauth_token']; $user->twitter_oauth_token_secret = $oauth_verifier['oauth_token_secret']; $user->registration_date = date("Y-m-d H:i:s"); $user->save(); /** * Update social meta key */ $UserMeta = Usermetum::find_by_user_id_and_meta_key_and_meta_value($user->user_id, 'social_type', 'twitter'); if (sizeof($UserMeta) <= 0) { $UserMeta = new Usermetum(); } $UserMeta->user_id = $user->user_id; $UserMeta->meta_key = 'social_type'; $UserMeta->meta_value = 'twitter'; $UserMeta->save(); /** * Update social meta value */ $UserMeta = Usermetum::find_by_user_id_and_meta_key_and_meta_value($user->user_id, 'social_id', $user_info->id); if (sizeof($UserMeta) <= 0) { $UserMeta = new Usermetum(); } $UserMeta->user_id = $user->user_id; $UserMeta->meta_key = 'social_id'; $UserMeta->meta_value = $user_info->id; $UserMeta->save(); /** * Save twitter user meta */ $UserMeta = Usermetum::find('first', array('user_id' => $user->user_id, 'meta_key' => 'twitter_meta')); if (sizeof($UserMeta) <= 0) { $UserMeta = new Usermetum(); } $UserMeta->user_id = $user->user_id; $UserMeta->meta_key = 'twitter_meta'; $UserMeta->meta_value = serialize($user_info); $UserMeta->save(); /** * Update graph table content */ $graph = Graph::find_by_user_id_and_date($user->user_id, date("Y-m-d")); if (sizeof($graph) <= 0) { $graph = new Graph(); $graph->user_id = $user->user_id; $graph->followers = $followers; $graph->social = 10; $graph->webclicks = 10; $graph->coupon = 10; $graph->date = date("Y-m-d"); $graph->save(); } else { $graph->followers = $followers; $graph->save(); } // see if we have a session $_SESSION['login'] = array('user_id' => $user->user_id, 'email' => $user_info->id, 'user_level' => 1, 'first_name' => $user_info->screen_name, 'last_name' => $user_info->screen_name, 'social_type' => 'twitter', 'oauth_verifier' => $oauth_verifier); $response = array('status' => 'success', 'url' => base_url('Twitter')); } } return $response; }
} else { $metafile = ''; $ldp_location = $_base; } $_data = file_get_contents('php://input'); if ($_input == 'raw') { require_once 'if-match.php'; file_put_contents($_filename, $_data, FILE_APPEND | LOCK_EX); httpStatusExit(201, 'Created'); } $g = new Graph('', $_filename, '', $_base); require_once 'if-match.php'; if ($_method == 'PATCH') { if ($_input == 'json' && ($g->patch_json($_data) || 1)) { librdf_php_last_log_level() && httpStatusExit(400, 'Bad Request', null, librdf_php_last_log_message()); $g->save(); header('Triples: ' . $g->size()); header("Link: <" . dirname($_base) . '/' . $metafile . ">; rel=meta", false); header('Location: ' . $ldp_location); httpStatusExit(201, 'Created'); } } elseif (!empty($_input) && ($g->append($_input, $_data) || 1)) { librdf_php_last_log_level() && httpStatusExit(400, 'Bad Request', null, librdf_php_last_log_message()); $g->save(); header("Triples: " . $g->size(), false); header("Link: <" . $_base . $metafile . ">; rel=meta", false); header('Location: ' . $ldp_location); header('ETag: "' . md5_file($_filename) . '"'); httpStatusExit(201, 'Created'); } elseif ($_content_type == 'application/sparql-update') { require_once 'SPARQL.php';
exit; } // add a PrimaryTopic $document->append_objects($BASE . '/' . $profile, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', array(array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/PersonalProfileDocument'))); $document->append_objects($BASE . '/' . $profile, 'http://xmlns.com/foaf/0.1/primaryTopic', array(array('type' => 'uri', 'value' => $webid))); // add a foaf:Person $document->append_objects($webid, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', array(array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Person'))); // add name $document->append_objects($webid, 'http://xmlns.com/foaf/0.1/name', array(array('type' => 'literal', 'value' => $name))); // add mbox if we have one if (strlen($email) > 0) { $document->append_objects($webid, 'http://xmlns.com/foaf/0.1/mbox', array(array('type' => 'uri', 'value' => 'mailto:' . $email))); } // add avatar if we have one if (strlen($pic) > 0) { $document->append_objects($webid, 'http://xmlns.com/foaf/0.1/img', array(array('type' => 'uri', 'value' => $pic))); } // ---- Add workspaces ---- // add shared storage space $document->append_objects($webid, 'http://www.w3.org/ns/pim/space#storage', array(array('type' => 'uri', 'value' => $storage_uri))); // ---- Certificate ---- // add modulus and exponent as bnode $document->append_objects($webid, 'http://www.w3.org/ns/auth/cert#key', array(array('type' => 'bnode', 'value' => '_:bnode1'))); $document->append_objects('_:bnode1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', array(array('type' => 'uri', 'value' => 'http://www.w3.org/ns/auth/cert#RSAPublicKey'))); if (isset($modulus)) { $document->append_objects('_:bnode1', 'http://www.w3.org/ns/auth/cert#modulus', array(array('type' => 'literal', 'value' => $modulus, 'datatype' => 'http://www.w3.org/2001/XMLSchema#hexBinary'))); } $document->append_objects('_:bnode1', 'http://www.w3.org/ns/auth/cert#exponent', array(array('type' => 'literal', 'value' => '65537', 'datatype' => 'http://www.w3.org/2001/XMLSchema#int'))); $document->save(); // ------ DONE WITH PROFILE ------- }