/**
 * Adds an item to the river.
 *
 * @param string $view The view that will handle the river item (must exist)
 * @param string $action_type An arbitrary one-word string to define the action (eg 'comment', 'create')
 * @param int $subject_guid The GUID of the entity doing the action
 * @param int $object_guid The GUID of the entity being acted upon
 * @param int $access_id The access ID of the river item (default: same as the object) 
 * @param int $posted The UNIX epoch timestamp of the river item (default: now)
 * @return true|false Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0)
{
    // Sanitise variables
    if (!elgg_view_exists($view)) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    return insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " posted = {$posted} ");
}
Example #2
0
/**
 * Adds an item to the river.
 *
 * @param string $view The view that will handle the river item (must exist)
 * @param string $action_type An arbitrary one-word string to define the action (eg 'comment', 'create')
 * @param int $subject_guid The GUID of the entity doing the action
 * @param int $object_guid The GUID of the entity being acted upon
 * @param int $access_id The access ID of the river item (default: same as the object)
 * @param int $posted The UNIX epoch timestamp of the river item (default: now)
 * @return true|false Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    // Sanitise variables
    if (!elgg_view_exists($view)) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $annotation_id = (int) $annotation_id;
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    $insert_data = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted} ");
    //update the entities which had the action carried out on it
    if ($insert_data) {
        update_entity_last_action($object_guid, $posted);
        return $insert_data;
    }
}
Example #3
0
/**
 * Define an arbitrary relationship between two entities.
 * This relationship could be a friendship, a group membership or a site membership.
 *
 * This function lets you make the statement "$guid_one is a $relationship of $guid_two".
 *
 * @param int    $guid_one     First GUID
 * @param string $relationship Relationship name
 * @param int    $guid_two     Second GUID
 *
 * @return bool
 * @throws InvalidArgumentException
 */
function add_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    if (strlen($relationship) > ElggRelationship::RELATIONSHIP_LIMIT) {
        $msg = "relationship name cannot be longer than " . ElggRelationship::RELATIONSHIP_LIMIT;
        throw InvalidArgumentException($msg);
    }
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $time = time();
    // Check for duplicates
    if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
        return false;
    }
    $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_relationships\n\t\t(guid_one, relationship, guid_two, time_created)\n\t\tVALUES ({$guid_one}, '{$relationship}', {$guid_two}, {$time})");
    if ($id !== false) {
        $obj = get_relationship($id);
        // this event has been deprecated in 1.9. Use 'create', 'relationship'
        $result_old = elgg_trigger_event('create', $relationship, $obj);
        $result = elgg_trigger_event('create', 'relationship', $obj);
        if ($result && $result_old) {
            return true;
        } else {
            delete_relationship($result);
        }
    }
    return false;
}
Example #4
0
 public function testCanInsertData()
 {
     _elgg_services()->db->addQuerySpec(['sql' => 'INSERT INTO A WHERE b = :b', 'params' => [':b' => 'b'], 'insert_id' => 123]);
     _elgg_services()->db->addQuerySpec(['sql' => 'INSERT INTO A WHERE c = :c', 'params' => [':c' => 'c']]);
     $this->assertEquals(123, insert_data('INSERT INTO A WHERE b = :b', [':b' => 'b']));
     $this->assertEquals(0, insert_data('INSERT INTO A WHERE c = :c', [':c' => 'c']));
 }
Example #5
0
function addTaggedWirePost($hook, $type, $params)
{
    global $CONFIG;
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '" . $params['type'] . "', " . " subtype = '" . $params['subtype'] . "', " . " action_type = '" . $params['action_type'] . "', " . " access_id = '" . $params['access_id'] . "', " . " view = '" . $params['view'] . "', " . " subject_guid = '" . $params['subject_guid'] . "', " . " object_guid = '" . $params['object_guid'] . "', " . " annotation_id = '" . $params['annotation_id'] . "', " . " posted = '" . $params['posted'] . "';");
    $tags = "";
    if (isset($_SESSION['role'])) {
        switch ($_SESSION['role']) {
            case "learner":
                $tags = "Learner-Apprenant";
                break;
            case "instructor":
                $tags = "Instructor-Instructeur";
                break;
            case "developer":
                $tags = "Developer-Développeur";
                break;
            case "trainingmgr":
                $tags = "trainingmgr";
                break;
        }
        $roleTags = $_SESSION['role'];
    }
    if ($roleTags) {
        $metaID = create_metadata($params['object_guid'], "tags", "{$tags}", "text", elgg_get_logged_in_user_guid(), 2, true);
    }
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
    }
    return false;
}
/**
 * Create or update the extras table for a given object.
 * Call create_entity first.
 *
 * @param int    $guid        The guid of the entity you're creating (as obtained by create_entity)
 * @param string $title       The title of the object
 * @param string $description The object's description
 *
 * @return bool
 */
function create_object_entity($guid, $title, $description)
{
    global $CONFIG;
    $guid = (int) $guid;
    $title = sanitise_string($title);
    $description = sanitise_string($description);
    $row = get_entity_as_row($guid);
    if ($row) {
        // Core entities row exists and we have access to it
        $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}";
        if ($exists = get_data_row($query)) {
            $query = "UPDATE {$CONFIG->dbprefix}objects_entity\n\t\t\t\tset title='{$title}', description='{$description}' where guid={$guid}";
            $result = update_data($query);
            if ($result != false) {
                // Update succeeded, continue
                $entity = get_entity($guid);
                elgg_trigger_event('update', $entity->type, $entity);
                return $guid;
            }
        } else {
            // Update failed, attempt an insert.
            $query = "INSERT into {$CONFIG->dbprefix}objects_entity\n\t\t\t\t(guid, title, description) values ({$guid}, '{$title}','{$description}')";
            $result = insert_data($query);
            if ($result !== false) {
                $entity = get_entity($guid);
                if (elgg_trigger_event('create', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                }
            }
        }
    }
    return false;
}
Example #7
0
 /**
  * Save a key
  *
  * @param string $key  Name
  * @param string $data Value
  *
  * @return boolean
  */
 public function save($key, $data)
 {
     $dbprefix = elgg_get_config('dbprefix');
     $key = sanitise_string($key);
     $time = time();
     $query = "INSERT into {$dbprefix}hmac_cache (hmac, ts) VALUES ('{$key}', '{$time}')";
     return insert_data($query);
 }
Example #8
0
 /**
  * Save a key
  *
  * @param string $key  Name
  * @param string $data Value
  *
  * @return boolean
  */
 public function save($key, $data)
 {
     global $CONFIG;
     $key = sanitise_string($key);
     $time = time();
     $query = "INSERT into {$CONFIG->dbprefix}hmac_cache (hmac, ts) VALUES ('{$key}', '{$time}')";
     return insert_data($query);
 }
Example #9
0
function add($conn)
{
    //echo "you got add";
    $realname = $_GET["real_name"];
    $user = $_GET["user"];
    $pass = $_GET["pass"];
    insert_data($conn, $realname, $user, $pass);
}
Example #10
0
function add($conn)
{
    $employee = $_GET["employee"];
    $product = $_GET["product"];
    $brand = $_GET["brand"];
    $quantity = $_GET["quantity"];
    $price = $_GET["price"];
    insert_data($conn, $employee, $product, $brand, $quantity, $price);
}
Example #11
0
function eg_chat_post($chatp_guid, $chat_post)
{
    error_log('here is chatpost - ' . $chat_post);
    $userid = elgg_get_logged_in_user_guid();
    $query = "insert into  `chathistory` (`to_guid`,`from_guid`,`message`,`date`) values('" . $chatp_guid . "','" . $userid . "','" . $chat_post . "','" . date('Y-m-d H:i') . "')";
    insert_data($query);
    $last_record_id = "select `id` from `chathistory` where `from_guid`=" . $userid . " order by id desc limit 1";
    $aj = get_data($last_record_id);
    return json_encode($aj);
}
Example #12
0
 /**
  * Generate a new API user for a site, returning a new keypair on success
  * @return \hypeJunction\Graph\ApiUser|false
  */
 public function create()
 {
     $public = sha1(rand() . $this->site_guid . microtime());
     $secret = sha1(rand() . $this->site_guid . microtime() . $public);
     $insert = insert_data("INSERT into {$this->dbprefix}api_users\n\t\t\t\t\t\t\t\t(site_guid, api_key, secret) values\n\t\t\t\t\t\t\t\t({$this->site_guid}, '{$public}', '{$secret}')");
     if (empty($insert)) {
         return false;
     }
     return $this->get($public);
 }
Example #13
0
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 *
 * @return int/bool River ID or false on failure
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    global $CONFIG;
    // use default viewtype for when called from web services api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    // Attempt to save river item; return success status
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be down elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Example #14
0
/**
 * Generate a new API user for a site, returning a new keypair on success.
 *
 * @return stdClass object or false
 */
function create_api_user()
{
    $dbprefix = elgg_get_config('dbprefix');
    $public = _elgg_services()->crypto->getRandomString(40, ElggCrypto::CHARS_HEX);
    $secret = _elgg_services()->crypto->getRandomString(40, ElggCrypto::CHARS_HEX);
    $insert = insert_data("INSERT into {$dbprefix}api_users\n\t\t(api_key, secret) values\n\t\t('{$public}', '{$secret}')");
    if ($insert) {
        return get_api_user($public);
    }
    return false;
}
Example #15
0
function gc_err_logging($errMess, $errStack, $applName, $errType)
{
    $DBprefix = elgg_get_config('dbprefix');
    $errDate = date("Y-m-d H:i:s");
    $servername = gethostname();
    $username = elgg_get_logged_in_user_entity()->username;
    $user_guid = elgg_get_logged_in_user_entity()->guid;
    $serverip = $_SERVER['REMOTE_ADDR'];
    $sql = 'INSERT INTO ' . $DBprefix . 'elmah_log (appl_name,error_type,server_name,server_ip,user_guid,time_created,username,error_messages,error_stacktrace) VALUES ("' . $applName . '","' . $errType . '","' . $servername . '","' . $serverip . '","' . $user_guid . '","' . $errDate . '","' . $username . '","' . $errMess . '","' . $errStack . '")';
    insert_data($sql);
}
Example #16
0
 /**
  * Obtain a token for a user
  *
  * @param ElggUser $user    User entity
  * @param ElggSite $site    Site entity token applies to
  * @param int       $expire Minutes until token expires (default is 60 minutes)
  * @return UserToken|false
  */
 public function create(ElggUser $user, ElggSite $site, $expire = self::DEFAULT_EXPIRES)
 {
     $time = time();
     $time += 60 * $expire;
     $token = md5(sha1(rand() . microtime() . $user->username . $time . $site->guid));
     $result = insert_data("INSERT into {$this->dbprefix}users_apisessions\n\t\t\t\t(user_guid, site_guid, token, expires) values\n\t\t\t\t({$user->guid}, {$site->guid}, '{$token}', '{$time}')\n\t\t\t\ton duplicate key update token='{$token}', expires='{$time}'");
     if (!$result) {
         return false;
     }
     return UserToken::load($token);
 }
Example #17
0
/**
 * Sets a configuration value
 *
 * @param string $name The name of the configuration value
 * @param string $value Its value
 * @param int $site_guid Optionally, the GUID of the site (current site is assumed by default)
 * @return 0
 * @todo The config table doens't have numeric primary keys so insert_data returns 0.
 */
function set_config($name, $value, $site_guid = 0)
{
    global $CONFIG;
    // Unset existing
    unset_config($name, $site_guid);
    $site_guid = (int) $site_guid;
    if ($site_guid == 0) {
        $site_guid = (int) $CONFIG->site_id;
    }
    $CONFIG->{$name} = $value;
    $value = sanitise_string(serialize($value));
    return insert_data("insert into {$CONFIG->dbprefix}config set name = '{$name}', value = '{$value}', site_guid = {$site_guid}");
}
Example #18
0
 public function testCanInsert()
 {
     $time = time();
     $id1 = insert_data("\n\t\t\tINSERT INTO {$this->prefix}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES ({$this->user->guid}, 'test_self1', {$this->user->guid}, {$time})\n\t\t\tON DUPLICATE KEY UPDATE time_created = {$time}\n\t\t");
     $id2 = insert_data("\n\t\t\tINSERT INTO {$this->prefix}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES (:guid1,   :rel,         :guid2,   :time)\n\t\t\tON DUPLICATE KEY UPDATE time_created = :time\n\t\t", [':guid1' => $this->user->guid, ':guid2' => $this->user->guid, ':rel' => 'test_self2', ':time' => $time]);
     $rows = get_data("\n\t\t\tSELECT *\n\t\t\tFROM {$this->prefix}entity_relationships\n\t\t\tWHERE guid_one = ?\n\t\t\t  AND guid_two = ?\n\t\t\t  AND time_created = ?\n\t\t\tORDER BY id ASC\n\t\t", null, [$this->user->guid, $this->user->guid, $time]);
     $this->assertIsA($id1, 'int');
     $this->assertIsA($id2, 'int');
     $this->assertEqual($rows[0]->id, $id1);
     $this->assertEqual($rows[1]->id, $id2);
     remove_entity_relationship($this->user->guid, 'test_self1', $this->user->guid);
     remove_entity_relationship($this->user->guid, 'test_self2', $this->user->guid);
 }
Example #19
0
File: tokens.php Project: elgg/elgg
/**
 * Obtain a token for a user.
 *
 * @param string $username The username
 * @param int    $expire   Minutes until token expires (default is 60 minutes)
 *
 * @return bool
 */
function create_user_token($username, $expire = 60)
{
    $dbprefix = elgg_get_config('dbprefix');
    $user = get_user_by_username($username);
    $time = time() + 60 * $expire;
    $token = _elgg_services()->crypto->getRandomString(32, ElggCrypto::CHARS_HEX);
    if (!$user) {
        return false;
    }
    if (insert_data("INSERT into {$dbprefix}users_apisessions\n\t\t\t\t(user_guid, token, expires) values\n\t\t\t\t({$user->guid}, '{$token}', '{$time}')\n\t\t\t\ton duplicate key update token='{$token}', expires='{$time}'")) {
        return $token;
    }
    return false;
}
Example #20
0
function entity_view_counter_add_view(ElggEntity $entity)
{
    if (entity_view_counter_is_counted($entity)) {
        return;
    }
    if (is_memcache_available()) {
        $cache = new ElggMemcache('entity_view_counter');
        $key = "view_" . session_id() . "_" . $entity->guid;
        $cache->save($key, 1);
    }
    $guid = (int) $entity->guid;
    $type = sanitise_string($entity->type);
    $subtype = (int) $entity->subtype;
    insert_data("\r\n    \tINSERT INTO elgg_entity_views (guid, type, subtype, container_guid, site_guid, views)\r\n    \tVALUES ({$guid}, '{$type}', {$subtype}, {$entity->container_guid}, {$entity->site_guid}, 1)\r\n    \tON DUPLICATE KEY UPDATE views = views + 1;\r\n    ");
}
Example #21
0
/**
 * Generate a new API user for a site, returning a new keypair on success.
 *
 * @param int $site_guid The GUID of the site. (default is current site)
 *
 * @return stdClass object or false
 */
function create_api_user($site_guid)
{
    global $CONFIG;
    if (!isset($site_guid)) {
        $site_guid = $CONFIG->site_id;
    }
    $site_guid = (int) $site_guid;
    $public = sha1(rand() . $site_guid . microtime());
    $secret = sha1(rand() . $site_guid . microtime() . $public);
    $insert = insert_data("INSERT into {$CONFIG->dbprefix}api_users\n\t\t(site_guid, api_key, secret) values\n\t\t({$site_guid}, '{$public}', '{$secret}')");
    if ($insert) {
        return get_api_user($site_guid, $public);
    }
    return false;
}
Example #22
0
/**
 * Obtain a token for a user.
 *
 * @param string $username The username
 * @param int    $expire   Minutes until token expires (default is 60 minutes)
 *
 * @return bool
 */
function create_user_token($username, $expire = 60)
{
    global $CONFIG;
    $site_guid = $CONFIG->site_id;
    $user = get_user_by_username($username);
    $time = time();
    $time += 60 * $expire;
    $token = md5(rand() . microtime() . $username . $time . $site_guid);
    if (!$user) {
        return false;
    }
    if (insert_data("INSERT into {$CONFIG->dbprefix}users_apisessions\n\t\t\t\t(user_guid, site_guid, token, expires) values\n\t\t\t\t({$user->guid}, {$site_guid}, '{$token}', '{$time}')\n\t\t\t\ton duplicate key update token='{$token}', expires='{$time}'")) {
        return $token;
    }
    return false;
}
/**
 * Set session geopositioning
 * Cache geocode along the way
 * 
 * @param string $location
 * @param float $latitude
 * @param float $longitude
 * @return void
 */
function set_geopositioning($location = '', $latitude = 0, $longitude = 0)
{
    $location = sanitize_string($location);
    $lat = (double) $latitude;
    $long = (double) $longitude;
    $latlong = elgg_geocode_location($location);
    if ($latlong) {
        $latitude = elgg_extract('lat', $latlong);
        $longitude = elgg_extract('long', $latlong);
    } else {
        if ($location && $latitude && $longitude) {
            $dbprefix = elgg_get_config('dbprefix');
            $query = "INSERT INTO {$dbprefix}geocode_cache\n\t\t\t\t(location, lat, `long`) VALUES ('{$location}', '{$lat}', '{$long}')\n\t\t\t\tON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'";
            insert_data($query);
        }
    }
    $_SESSION['geopositioning'] = array('location' => $location, 'latitude' => (double) $latitude, 'longitude' => (double) $longitude);
}
Example #24
0
File: users.php Project: rasul/Elgg
/**
 * Create or update the entities table for a given user.
 * Call create_entity first.
 *
 * @param int    $guid     The user's GUID
 * @param string $name     The user's display name
 * @param string $username The username
 * @param string $password The password
 * @param string $salt     A salt for the password
 * @param string $email    The user's email address
 * @param string $language The user's default language
 * @param string $code     A code
 *
 * @return bool
 */
function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code)
{
    global $CONFIG;
    $guid = (int) $guid;
    $name = sanitise_string($name);
    $username = sanitise_string($username);
    $password = sanitise_string($password);
    $salt = sanitise_string($salt);
    $email = sanitise_string($email);
    $language = sanitise_string($language);
    $code = sanitise_string($code);
    $row = get_entity_as_row($guid);
    if ($row) {
        // Exists and you have access to it
        $query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}";
        if ($exists = get_data_row($query)) {
            $query = "UPDATE {$CONFIG->dbprefix}users_entity\n\t\t\t\tset name='{$name}', username='******', password='******', salt='{$salt}',\n\t\t\t\temail='{$email}', language='{$language}', code='{$code}', last_action = " . time() . " where guid = {$guid}";
            $result = update_data($query);
            if ($result != false) {
                // Update succeeded, continue
                $entity = get_entity($guid);
                if (elgg_trigger_event('update', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                }
            }
        } else {
            // Update failed, attempt an insert.
            $query = "INSERT into {$CONFIG->dbprefix}users_entity\n\t\t\t\t(guid, name, username, password, salt, email, language, code)\n\t\t\t\tvalues ({$guid}, '{$name}', '{$username}', '{$password}', '{$salt}', '{$email}', '{$language}', '{$code}')";
            $result = insert_data($query);
            if ($result !== false) {
                $entity = get_entity($guid);
                if (elgg_trigger_event('create', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                    //delete_entity($guid);
                }
            }
        }
    }
    return false;
}
Example #25
0
File: river.php Project: rasul/Elgg
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 *
 * @return bool Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    // use default viewtype for when called from REST api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $annotation_id = (int) $annotation_id;
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    $params = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $params = elgg_trigger_plugin_hook('add', 'river', null, $params);
    if ($params == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($params);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    $insert_data = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    //update the entities which had the action carried out on it
    if ($insert_data) {
        update_entity_last_action($object_guid, $posted);
        return $insert_data;
    }
}
Example #26
0
/**
 * Create or update the entities table for a given site.
 * Call create_entity first.
 *
 * @param int    $guid        Site GUID
 * @param string $name        Site name
 * @param string $description Site Description
 * @param string $url         URL of the site
 *
 * @return bool
 * @access private
 */
function create_site_entity($guid, $name, $description, $url)
{
    global $CONFIG;
    $guid = (int) $guid;
    $name = sanitise_string($name);
    $description = sanitise_string($description);
    $url = sanitise_string($url);
    $row = get_entity_as_row($guid);
    if ($row) {
        // Exists and you have access to it
        $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}";
        if ($exists = get_data_row($query)) {
            $query = "UPDATE {$CONFIG->dbprefix}sites_entity\n\t\t\t\tset name='{$name}', description='{$description}', url='{$url}' where guid={$guid}";
            $result = update_data($query);
            if ($result != false) {
                // Update succeeded, continue
                $entity = get_entity($guid);
                if (elgg_trigger_event('update', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                    //delete_entity($guid);
                }
            }
        } else {
            // Update failed, attempt an insert.
            $query = "INSERT into {$CONFIG->dbprefix}sites_entity\n\t\t\t\t(guid, name, description, url) values ({$guid}, '{$name}', '{$description}', '{$url}')";
            $result = insert_data($query);
            if ($result !== false) {
                $entity = get_entity($guid);
                if (elgg_trigger_event('create', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                    //delete_entity($guid);
                }
            }
        }
    }
    return false;
}
/**
 * Define an arbitrary relationship between two entities.
 * This relationship could be a friendship, a group membership or a site membership.
 *
 * This function lets you make the statement "$guid_one is a $relationship of $guid_two".
 *
 * @param int    $guid_one     First GUID
 * @param string $relationship Relationship name
 * @param int    $guid_two     Second GUID
 *
 * @return bool
 */
function add_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $time = time();
    // Check for duplicates
    if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
        return false;
    }
    $result = insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships\n\t\t(guid_one, relationship, guid_two, time_created)\n\t\tvalues ({$guid_one}, '{$relationship}', {$guid_two}, {$time})");
    if ($result !== false) {
        $obj = get_relationship($result);
        if (elgg_trigger_event('create', $relationship, $obj)) {
            return true;
        } else {
            delete_relationship($result);
        }
    }
    return false;
}
Example #28
0
/**
 * DB Based session handling code.
 */
function __elgg_session_write($id, $sess_data)
{
    global $DB_PREFIX;
    $id = sanitise_string($id);
    $time = time();
    try {
        $sess_data_sanitised = sanitise_string($sess_data);
        if (insert_data("REPLACE INTO {$DB_PREFIX}users_sessions (session, ts, data) VALUES ('{$id}', '{$time}', '{$sess_data_sanitised}')") !== false) {
            return true;
        }
    } catch (DatabaseException $e) {
        // Fall back to file store in this case, since this likely means that the database hasn't been upgraded
        global $sess_save_path;
        $sess_file = "{$sess_save_path}/sess_{$id}";
        if ($fp = @fopen($sess_file, "w")) {
            $return = fwrite($fp, $sess_data);
            fclose($fp);
            return $return;
        }
    }
    return false;
}
Example #29
0
<?php

/**
 * AlQuran Doa API
 * @author Shahriar
 * @version 1.0.1
*/
$data = json_decode(file_get_contents("php://input"));
if (!$data) {
    die;
}
$sub = mysql_real_escape_string($data->sub);
if ($sub == 'addDoa') {
    // Add New Doa
    $args = array('doa_name' => $data->doaName, 'doa_details' => $data->doaDet, 'doa_lang' => $data->doaLang, 'doa_type' => $data->doaType);
    $chk = insert_data('q_doa', $args);
    if ($chk) {
        echo success_json();
    } else {
        echo err_json();
    }
} elseif ($sub == 'getDoa') {
    // Get all Doa list
    print_r(table_data('q_doa', '1', 'doa_id,doa_name,doa_type,doa_lang'));
} elseif ($sub == 'delDoa') {
    // Delete Doa
    $chk = delete_data('q_Doa', "doa_id='{$data->doaID}'");
    if ($chk) {
        success_json();
    } else {
        echo err_json();
Example #30
0
function import_csv()
{
    $db = mysql_connect("localhost", "garantma_user", "crKAyqBMMaEq");
    mysql_select_db("garantma_db", $db);
    //$db=mysql_connect("localhost", "root", "");
    //mysql_select_db("garantmarket", $db);
    // создание таблицы если ее нет... иначе проверяем и сравниваем данные в таблицах
    $query = 'CREATE TABLE temp (
  id INT NOT NULL AUTO_INCREMENT,
  iditem  TEXT NOT NULL,
  name  TEXT NOT NULL,
  space1  TEXT ,
  space2 TEXT ,
  price  INT ,
  manufected  TEXT ,
  category  TEXT ,
  keywords TEXT ,
  image TEXT ,
  vip INT ,
  levl INT ,
  public TEXT ,
  chpu TEXT ,
  h1 TEXT ,
  title TEXT ,
  description TEXT,
  rating TEXT,
  share TEXT,
  view BOOL,
   PRIMARY KEY (id)
  )';
    //   $query_insert= "LOAD DATA INFILE 'c:/OpenServer/domains/localhost/admin/temp/temp.csv'
    //INTO TABLE temp
    //FIELDS TERMINATED BY ';'
    //ENCLOSED BY '\"'
    //LINES TERMINATED BY '\r\n'
    //IGNORE 1 ROWS
    //(id,iditem,name,price,manufected,category,keywords,image,vip,levl,public,chpu,h1,title ,description,share)";
    //
    $query_update = "UPDATE catalog as s, temp as n\nSET \ns.name=n.name,\ns.price=n.price,\ns.keywords=n.keywords,\ns.vip=n.vip,\ns.levl=n.levl,\ns.publick=n.public,\ns.chpu=n.chpu,\ns.h1=n.h1,\ns.title=n.title,\ns.description=n.description,\ns.rating=n.rating,\ns.share=n.share,\ns.view=n.view\nWHERE s.iditem=n.iditem";
    $query_drop = "DROP TABLE temp";
    //___________________________________________ вставка в таблицу temp из файла
    function insert_data()
    {
        if ($file = fopen('temp/temp.csv', 'r')) {
            while (!feof($file)) {
                $line_csv = fgets($file);
                $line_csv = str_getcsv($line_csv, ';');
                $query_insert = "INSERT INTO temp( iditem,name,price, manufected,\n            category,keywords,image,vip,levl,public,chpu,h1,title,description,rating,share,view) VALUES \n            ('" . $line_csv[1] . "','" . $line_csv[2] . "','" . $line_csv[5] . "','" . $line_csv[6] . "','" . $line_csv[7] . "','" . $line_csv[8] . "     ','" . $line_csv[9] . "','" . $line_csv[10] . "','" . $line_csv[11] . "','" . $line_csv[12] . "','" . $line_csv[13] . "','" . $line_csv[14] . "','" . $line_csv[15] . "','" . $line_csv[16] . "','" . $line_csv[17] . "','" . $line_csv[18] . "','" . $line_csv[19] . "')";
                if (!mysql_query($query_insert)) {
                    echo mysql_errno() . mysql_error();
                }
            }
            fclose($file);
        } else {
            echo "ERROR READ FILE";
        }
    }
    if (!mysql_query($query_drop)) {
        echo mysql_errno() . mysql_error();
    }
    if (!mysql_query($query)) {
        echo mysql_errno() . mysql_error();
    }
    insert_data();
    if (!mysql_query($query_update)) {
        echo mysql_errno() . mysql_error();
    }
    return true;
}