Esempio n. 1
0
 public function actionCreate($location = null)
 {
     $project = new Project();
     $project->location_id = $location;
     $project->created_by_user_id = Yii::app()->user->id;
     $project->champs = array($project->created_by_user_id);
     if (!isset($_POST['Project'])) {
         $this->render('create', array('model' => $project));
         Yii::app()->end();
     }
     $project->attributes = $_POST['Project'];
     $project->slug = slugify($project->name);
     if (isset($_POST['ajax'])) {
         echo CActiveForm::validate($project, null, false);
         Yii::app()->end();
     }
     if (!$project->validate()) {
         $this->render('create', array('model' => $project));
         Yii::app()->end();
     }
     $feed = new Feed();
     $feed->followers = array($project->created_by_user_id);
     $feed->save();
     $project->feed_id = $feed->id;
     if (!$project->save()) {
         Yii::log('Project::save() failed. $errors = ' . print_r($project->getErrors(), true), 'error', 'app.project.create');
         $form->addError('save', 'Failed save the new project.');
         $this->render('create', array('model' => $project));
         $feed->delete();
         Yii::app()->end();
     }
     $this->renderText('window.parent.location = "' . $this->createUrl('view', array('id' => $project->id)) . '";');
 }
Esempio n. 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Region();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Region'])) {
         $model->attributes = $_POST['Region'];
         if (null === $model->slug || '' === $model->slug) {
             $model->slug = slugify($model->name);
         }
         $feed = new Feed();
         $feed->save();
         $model->feed_id = $feed->id;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $feed->delete();
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 3
0
function feed_controller()
{
    global $mysqli, $redis, $session, $route, $feed_settings;
    $result = false;
    require_once "Modules/feed/feed_model.php";
    $feed = new Feed($mysqli, $redis, $feed_settings);
    if ($route->format == 'html') {
        if ($route->action == "list" && $session['write']) {
            $result = view("Modules/feed/Views/feedlist_view.php", array());
        } else {
            if ($route->action == "api" && $session['write']) {
                $result = view("Modules/feed/Views/feedapi_view.php", array());
            }
        }
    } else {
        if ($route->format == 'json') {
            // Public actions available on public feeds.
            if ($route->action == "list") {
                if ($session['read']) {
                    if (!isset($_GET['userid']) || isset($_GET['userid']) && $_GET['userid'] == $session['userid']) {
                        $result = $feed->get_user_feeds($session['userid']);
                    } else {
                        if (isset($_GET['userid']) && $_GET['userid'] != $session['userid']) {
                            $result = $feed->get_user_public_feeds(get('userid'));
                        }
                    }
                } else {
                    if (isset($_GET['userid'])) {
                        $result = $feed->get_user_public_feeds(get('userid'));
                    }
                }
            } elseif ($route->action == "create" && $session['write']) {
                $result = $feed->create($session['userid'], get('tag'), get('name'), get('datatype'), get('engine'), json_decode(get('options')));
            } elseif ($route->action == "updatesize" && $session['write']) {
                $result = $feed->update_user_feeds_size($session['userid']);
            } elseif ($route->action == "buffersize" && $session['write']) {
                $result = $feed->get_buffer_size();
                // To "fetch" multiple feed values in a single request
                // http://emoncms.org/feed/fetch.json?ids=123,567,890
            } elseif ($route->action == "fetch" && $session['read']) {
                $feedids = (array) explode(",", get('ids'));
                for ($i = 0; $i < count($feedids); $i++) {
                    $feedid = (int) $feedids[$i];
                    if ($feed->exist($feedid)) {
                        // if the feed exists
                        $result[$i] = $feed->get_value($feedid);
                        // null is a valid response
                    } else {
                        $result[$i] = false;
                    }
                    // false means feed not found
                }
            } else {
                $feedid = (int) get('id');
                // Actions that operate on a single existing feed that all use the feedid to select:
                // First we load the meta data for the feed that we want
                if ($feed->exist($feedid)) {
                    $f = $feed->get($feedid);
                    // if public or belongs to user
                    if ($f['public'] || $session['userid'] > 0 && $f['userid'] == $session['userid'] && $session['read']) {
                        if ($route->action == "timevalue") {
                            $result = $feed->get_timevalue($feedid);
                        } else {
                            if ($route->action == 'data') {
                                $skipmissing = 1;
                                $limitinterval = 1;
                                if (isset($_GET['skipmissing']) && $_GET['skipmissing'] == 0) {
                                    $skipmissing = 0;
                                }
                                if (isset($_GET['limitinterval']) && $_GET['limitinterval'] == 0) {
                                    $limitinterval = 0;
                                }
                                $result = $feed->get_data($feedid, get('start'), get('end'), get('interval'), $skipmissing, $limitinterval);
                            } else {
                                if ($route->action == "value") {
                                    $result = $feed->get_value($feedid);
                                } else {
                                    if ($route->action == "get") {
                                        $result = $feed->get_field($feedid, get('field'));
                                    } else {
                                        if ($route->action == "aget") {
                                            $result = $feed->get($feedid);
                                        } else {
                                            if ($route->action == 'histogram') {
                                                $result = $feed->histogram_get_power_vs_kwh($feedid, get('start'), get('end'));
                                            } else {
                                                if ($route->action == 'kwhatpower') {
                                                    $result = $feed->histogram_get_kwhd_atpower($feedid, get('min'), get('max'));
                                                } else {
                                                    if ($route->action == 'kwhatpowers') {
                                                        $result = $feed->histogram_get_kwhd_atpowers($feedid, get('points'));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // write session required
                    if (isset($session['write']) && $session['write'] && $session['userid'] > 0 && $f['userid'] == $session['userid']) {
                        // Storage engine agnostic
                        if ($route->action == 'set') {
                            $result = $feed->set_feed_fields($feedid, get('fields'));
                        } else {
                            if ($route->action == "insert") {
                                $result = $feed->insert_data($feedid, time(), get("time"), get("value"));
                            } else {
                                if ($route->action == "update") {
                                    $result = $feed->update_data($feedid, time(), get("time"), get('value'));
                                } else {
                                    if ($route->action == "delete") {
                                        $result = $feed->delete($feedid);
                                    } else {
                                        if ($route->action == "getmeta") {
                                            $result = $feed->get_meta($feedid);
                                        } else {
                                            if ($route->action == "csvexport") {
                                                $result = $feed->csv_export($feedid, get('start'), get('end'), get('interval'), get('timeformat'));
                                            } else {
                                                if ($route->action == "process") {
                                                    if ($f['engine'] != Engine::VIRTUALFEED) {
                                                        $result = array('success' => false, 'message' => 'Feed is not Virtual');
                                                    } else {
                                                        if ($route->subaction == "get") {
                                                            $result = $feed->get_processlist($feedid);
                                                        } else {
                                                            if ($route->subaction == "set") {
                                                                $result = $feed->set_processlist($feedid, post('processlist'));
                                                            } else {
                                                                if ($route->subaction == "reset") {
                                                                    $result = $feed->reset_processlist($feedid);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if ($f['engine'] == Engine::MYSQL || $f['engine'] == Engine::MYSQLMEMORY) {
                            if ($route->action == "export") {
                                $result = $feed->mysqltimeseries_export($feedid, get('start'));
                            } else {
                                if ($route->action == "deletedatapoint") {
                                    $result = $feed->mysqltimeseries_delete_data_point($feedid, get('feedtime'));
                                } else {
                                    if ($route->action == "deletedatarange") {
                                        $result = $feed->mysqltimeseries_delete_data_range($feedid, get('start'), get('end'));
                                    }
                                }
                            }
                        } elseif ($f['engine'] == Engine::PHPTIMESERIES) {
                            if ($route->action == "export") {
                                $result = $feed->phptimeseries_export($feedid, get('start'));
                            }
                        } elseif ($f['engine'] == Engine::PHPFIWA) {
                            if ($route->action == "export") {
                                $result = $feed->phpfiwa_export($feedid, get('start'), get('layer'));
                            }
                        } elseif ($f['engine'] == Engine::PHPFINA) {
                            if ($route->action == "export") {
                                $result = $feed->phpfina_export($feedid, get('start'));
                            }
                        }
                    }
                } else {
                    $result = array('success' => false, 'message' => 'Feed does not exist');
                }
            }
        }
    }
    return array('content' => $result);
}
		function delete($id) {
			global $database, $db, $event;
			if (!preg_match("/^[0-9]+$/", $id)) {
				$id = User::loginid2id($id);
			}

			if (empty($id) || !isset($id)) {
				return false;
			}

			if (!$event->on('User.delete', array('id'=>$id)))
				return false;

			$db->query('SELECT id FROM '.$database['prefix'].'Feeds WHERE owner='.$id);
			while ($data = $db->fetch()) {
				Feed::delete($data->id);
			}
			$db->free();
			
			return $db->execute('DELETE FROM '.$database['prefix'].'Users WHERE id="'.$id.'"');
		}
Esempio n. 5
0
function feed_controller()
{
    global $mysqli, $redis, $session, $route, $feed_settings;
    $result = false;
    include "Modules/feed/feed_model.php";
    $feed = new Feed($mysqli, $redis, $feed_settings);
    if ($route->format == 'html') {
        if ($route->action == "list" && $session['write']) {
            $result = view("Modules/feed/Views/feedlist_view.php", array());
        }
        if ($route->action == "api" && $session['write']) {
            $result = view("Modules/feed/Views/feedapi_view.php", array());
        }
    }
    if ($route->format == 'json') {
        // Public actions available on public feeds.
        if ($route->action == "list") {
            if (!isset($_GET['userid']) && $session['read']) {
                $result = $feed->get_user_feeds($session['userid']);
            }
            if (isset($_GET['userid']) && $session['read'] && $_GET['userid'] == $session['userid']) {
                $result = $feed->get_user_feeds($session['userid']);
            }
            if (isset($_GET['userid']) && $session['read'] && $_GET['userid'] != $session['userid']) {
                $result = $feed->get_user_public_feeds(get('userid'));
            }
            if (isset($_GET['userid']) && !$session['read']) {
                $result = $feed->get_user_public_feeds(get('userid'));
            }
        } elseif ($route->action == "getid" && $session['read']) {
            $result = $feed->get_id($session['userid'], get('name'));
        } elseif ($route->action == "create" && $session['write']) {
            $result = $feed->create($session['userid'], get('name'), get('datatype'), get('engine'), json_decode(get('options')));
        } elseif ($route->action == "updatesize" && $session['write']) {
            $result = $feed->update_user_feeds_size($session['userid']);
            // To "fetch" multiple feed values in a single request
            // http://emoncms.org/feed/fetch.json?ids=123,567,890
        } elseif ($route->action == "fetch" && $session['read']) {
            $feedids = (array) explode(",", get('ids'));
            for ($i = 0; $i < count($feedids); $i++) {
                $feedid = (int) $feedids[$i];
                if ($feed->exist($feedid)) {
                    $result[$i] = (double) $feed->get_value($feedid);
                } else {
                    $result[$i] = "";
                }
            }
        } else {
            $feedid = (int) get('id');
            // Actions that operate on a single existing feed that all use the feedid to select:
            // First we load the meta data for the feed that we want
            if ($feed->exist($feedid)) {
                $f = $feed->get($feedid);
                // if public or belongs to user
                if ($f['public'] || $session['userid'] > 0 && $f['userid'] == $session['userid'] && $session['read']) {
                    if ($route->action == "value") {
                        $result = $feed->get_value($feedid);
                    }
                    if ($route->action == "timevalue") {
                        $result = $feed->get_timevalue_seconds($feedid);
                    }
                    if ($route->action == "get") {
                        $result = $feed->get_field($feedid, get('field'));
                    }
                    // '/[^\w\s-]/'
                    if ($route->action == "aget") {
                        $result = $feed->get($feedid);
                    }
                    if ($route->action == 'histogram') {
                        $result = $feed->histogram_get_power_vs_kwh($feedid, get('start'), get('end'));
                    }
                    if ($route->action == 'kwhatpower') {
                        $result = $feed->histogram_get_kwhd_atpower($feedid, get('min'), get('max'));
                    }
                    if ($route->action == 'kwhatpowers') {
                        $result = $feed->histogram_get_kwhd_atpowers($feedid, get('points'));
                    }
                    if ($route->action == 'data') {
                        $result = $feed->get_data($feedid, get('start'), get('end'), get('dp'));
                    }
                    if ($route->action == 'average') {
                        $result = $feed->get_average($feedid, get('start'), get('end'), get('interval'));
                    }
                    if ($route->action == 'history') {
                        $result = $feed->get_history($feedid, get('start'), get('end'), get('interval'));
                    }
                }
                // write session required
                if (isset($session['write']) && $session['write'] && $session['userid'] > 0 && $f['userid'] == $session['userid']) {
                    // Storage engine agnostic
                    if ($route->action == 'set') {
                        $result = $feed->set_feed_fields($feedid, get('fields'));
                    }
                    if ($route->action == "insert") {
                        $result = $feed->insert_data($feedid, time(), get("time"), get("value"));
                    }
                    if ($route->action == "update") {
                        $result = $feed->update_data($feedid, time(), get("time"), get('value'));
                    }
                    if ($route->action == "delete") {
                        $result = $feed->delete($feedid);
                    }
                    if ($route->action == "getmeta") {
                        $result = $feed->get_meta($feedid);
                    }
                    if ($route->action == "csvexport") {
                        $feed->csv_export($feedid, get('start'), get('end'), get('interval'));
                    }
                    if ($f['engine'] == Engine::TIMESTORE) {
                        if ($route->action == "export") {
                            $result = $feed->timestore_export($feedid, get('start'), get('layer'));
                        }
                        if ($route->action == "exportmeta") {
                            $result = $feed->timestore_export_meta($feedid);
                        }
                        if ($route->action == "scalerange") {
                            $result = $feed->timestore_scale_range($feedid, get('start'), get('end'), get('value'));
                        }
                    } elseif ($f['engine'] == Engine::MYSQL) {
                        if ($route->action == "export") {
                            $result = $feed->mysqltimeseries_export($feedid, get('start'));
                        }
                        if ($route->action == "deletedatapoint") {
                            $result = $feed->mysqltimeseries_delete_data_point($feedid, get('feedtime'));
                        }
                        if ($route->action == "deletedatarange") {
                            $result = $feed->mysqltimeseries_delete_data_range($feedid, get('start'), get('end'));
                        }
                    } elseif ($f['engine'] == Engine::PHPTIMESERIES) {
                        if ($route->action == "export") {
                            $result = $feed->phptimeseries_export($feedid, get('start'));
                        }
                    } elseif ($f['engine'] == Engine::PHPFIWA) {
                        if ($route->action == "export") {
                            $result = $feed->phpfiwa_export($feedid, get('start'), get('layer'));
                        }
                    } elseif ($f['engine'] == Engine::PHPFINA) {
                        if ($route->action == "export") {
                            $result = $feed->phpfina_export($feedid, get('start'));
                        }
                    }
                }
            } else {
                $result = array('success' => false, 'message' => 'Feed does not exist');
            }
        }
    }
    return array('content' => $result);
}
Esempio n. 6
0
	$id = $_POST['id'];

	if(empty($id)) {
			$response['error'] = -1;
			$response['message'] = _t('잘못된 접근입니다.');
	} else {
		if (!isLoggedIn()) {
			$response['error'] = 1;
			$response['message'] = _t('로그인 한 사람만 이 기능을 사용할 수 있습니다.');
		} else {
			$ids = explode(',', $id);

			foreach($ids as $id) {	
				if(empty($id)) continue;

				$feed = Feed::getAll($id);
				
				if(isAdmin() || $feed['owner'] == getLoggedId()) {
					Feed::delete($id);
				} else {
					$response['error'] = -1;
					$response['message'] = _t('잘못된 접근입니다.');
					break;
				}
			}
		}
	}

	func::printRespond($response);
?>