Example #1
1
 function props_to_xml()
 {
     # make the source xml
     # make doc and root
     $xml = new DomDocument();
     $root = $xml->createElement('request');
     $root->setAttribute('controller', params('controller'));
     $root->setAttribute('action', params('action'));
     $root = $xml->appendChild($root);
     # unpack the props into xml
     foreach ($this->props as $k => $v) {
         # if it will become xml, do that, otherwise make a dumb tag
         if (is_object($v) && method_exists($v, 'to_xml')) {
             $obj_xml = $v->to_xml(array(), true, true);
             $obj_xml = $xml->importNode($obj_xml->documentElement, true);
             $root->appendChild($obj_xml);
         } else {
             $node = $xml->createElement($k);
             if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) {
                 $cdata = $xml->createCDATASection($v);
             } else {
                 $cdata = $xml->createTextNode($v);
             }
             $node->appendChild($cdata);
             $node = $root->appendChild($node);
         }
     }
     return $xml;
 }
Example #2
1
function GamePage()
{
    global $base_uri;
    $uid = params('user');
    if (!isset($_SESSION['uid'])) {
        return 0;
    } else {
        createToken($_SESSION['uid']);
    }
    $reg = 0;
    $shit = 0;
    if (!isset($uid) || $uid == "") {
        $uid = $_SESSION['uid'];
    } else {
        if (!check_registration($uid)) {
            $reg = 1;
        }
        $shit = 1;
    }
    $user = getUserInfo($_SESSION['access_token'], $uid, 'photo_max');
    if ($reg) {
        register($uid, $user['first_name'], $user['last_name']);
    }
    echo $user['first_name'] . " " . $user['last_name'];
    echo "<img src=\"" . $user['photo_max'] . "\" /><br><br>";
    if ($shit) {
        echo "<a href=\"/shit/" . $_SESSION['uid'] . "/" . $uid . "/" . getToken($_SESSION['uid']) . "\">shit</a><br>";
    }
    $friends = getUserFriends($_SESSION['access_token'], $uid);
    foreach ($friends as $friend) {
        echo $friend["first_name"] . " " . $friend["last_name"] . "<br>";
        echo "<a href=\"{$base_uri}/game/" . $friend['uid'] . "\"><img src=\"" . $friend["photo_50"] . "\" /></a><hr>";
    }
}
Example #3
0
function people_roles_delete()
{
    $cfg = $GLOBALS['cfg'];
    $db = $GLOBALS['db'];
    $role_id = intval(params('role_id'));
    $person_id = intval(params('person_id'));
    $connect = isset($_POST['connect']) ? true : false;
    if ($connect) {
        $role_id = intval($_POST['role_id']);
        $person_id = intval($_POST['person_id']);
    }
    $result = $db->delete("DELETE FROM {$cfg['tblPersonHasRole']}\n        WHERE rolle_id='{$role_id}'\n        AND person_id='{$person_id}'\n        LIMIT 1");
    if (!$result) {
        halt(SERVER_ERROR);
        return;
    }
    if (isAjaxRequest()) {
        if ($connect) {
            $arrRoles = fetchRoles("WHERE {$cfg['tblRole']}.id = {$role_id}");
            return js('people_roles/role.js.php', null, array('role' => array_pop($arrRoles)));
        } else {
            set('role', array('id' => $role_id));
            set('person', array('id' => $person_id));
            return js('people_roles/delete.js.php', null);
        }
    } else {
        halt(HTTP_NOT_IMPLEMENTED);
    }
}
Example #4
0
 /**
  *
  * @param type $form
  * @param type $type_id
  * @param type $rules
  * @return type 
  */
 public function form($id = '', $module_id = '')
 {
     $this->data['module_id'] = $module_id;
     if (!empty($id) and empty($_POST)) {
         $this->data['post'] = $this->post->find($id, 1);
     } else {
         $post = params(array('title', 'description', 'tags', 'category_id'));
         $post['id'] = $id;
         $this->data['data'] = $post;
     }
     $this->load->library('form_validation');
     $config = array(array('field' => 'title', 'label' => 'Заголовок топика', 'rules' => 'required|trim|max_length[255]'), array('field' => 'tags', 'label' => 'Тэги', 'rules' => 'required|trim|min_length[4]|max_length[255]'));
     $this->form_validation->set_rules($config);
     if ($this->form_validation->run($this) === FALSE) {
         $this->data['modules_for_add'] = $this->settings['modules'];
         if (!empty($id)) {
             $this->data['modules'] = $this->module->find_all_for_post($id);
             $post = $this->post->find($id, 1);
             $this->call_modules($post, $module_id);
         }
         $this->template->render_to('content', $this->view . 'form', $this->data);
     } else {
         $post['user_id'] = (int) $this->current_user['id'];
         $post['id'] = $this->post->save($post);
         if ($post['id']) {
             set_flash_ok('Отлично, топик создан, теперь можно его наполнять');
         } else {
             set_flash_error('Извини, ошибочка вышла');
         }
         redirect('post/form/' . $post['id']);
     }
     $this->draw();
 }
Example #5
0
function routing($routes)
{
    $url = $_SERVER['REQUEST_URI'];
    //echo $url.'<br/>';
    $url = str_replace("?" . $_SERVER['QUERY_STRING'], "", $url);
    /*echo $_SERVER['QUERY_STRING'].'<br/>';
    		echo $url.'<br/>';*/
    $params = params();
    //print_r($params)."<br/>";
    foreach ($routes as $route) {
        //echo $route["url"]."<br/>";
        if ($num_routes = preg_match($route["url"], $url, $matches) > 0) {
            $params = array_merge($matches, $params);
            break;
        }
    }
    print_r($params) . "<br/>";
    if ($num_routes == 0) {
        exit("No se ha encontrado la ruta");
    }
    if ($route["controller"] != "") {
        include CONTROLLERS_PATH . $route["controller"] . ".php";
    }
    if (file_exists(VIEWS_PATH . "layouts" . DS . $route["controller"] . ".php")) {
        include VIEWS_PATH . "layouts" . DS . $route["controller"] . ".php";
    } else {
        include VIEWS_PATH . "layouts" . DS . "default.php";
    }
    $_SESSION["msg"]["warnings"] = "";
    $_SESSION["msg"]["success"] = "";
}
Example #6
0
 function log($format = false, $address = false, $title = '')
 {
     $out = '';
     if ($format === false) {
         $format = self::$log_format;
     }
     switch ($format) {
         case 'text':
             $out .= $this->get_message() . "\n\n";
             break;
         case 'email':
         case 'mail':
             ob_start();
             echo $this->get_message();
             echo "\nFor URL: " . $_SERVER['REQUEST_URI'] . "\n\n";
             echo "With Reqeust:";
             var_export(params());
             echo "\n\n";
             echo "In " . $this->get_file() . " on line " . $this->get_line() . "\n";
             mail($address, $title . ': ' . get_class($this) . ' Error', ob_get_clean());
             break;
         case 'html':
             $out = $this->to_html();
             break;
         case 'xml':
             $out .= $this->to_xml();
             break;
         case 'silent':
             # do nothing
             break;
     }
     error_log("Exception in " . $this->get_file() . ":" . $this->get_line() . " - " . $this->get_message());
     return $out;
 }
Example #7
0
 function test_main_params()
 {
   assert_empty(params());
   assert_empty(params(null));
   assert_true(is_array(params()));
   
   assert_equal(params('first', 6), 6);
   assert_equal(params('first'), 6);
   assert_true(is_array(params()));
   assert_equal(params('first', 12), 12);
   assert_length_of(params(), 1);
   
   params('my_array', 1, 2, 3, 4);
   assert_true(is_array(params('my_array')));
   assert_length_of(params('my_array'), 4);
   
   assert_true(is_array(params()));
   assert_length_of(params(), 2);
   
   params(array('zero','one'));
   assert_length_of(params(), 4);
   assert_equal(params(0), 'zero');
   assert_equal(params(1), 'one');
   
   params(array(2 => 'two', 'first' => 'my one'));
   assert_length_of(params(), 5);
   assert_equal(params(2), 'two');
   assert_equal(params('first'), 'my one');
   
   assert_empty(params(null));
 }
Example #8
0
function daemons_servers_delete()
{
    $cfg = $GLOBALS['cfg'];
    $db = $GLOBALS['db'];
    $server_id = intval(params('server_id'));
    $daemon_id = intval(params('daemon_id'));
    $arrService = $db->select("SELECT id\n        FROM {$cfg['tblService']}\n        WHERE server_id='{$server_id}'\n        AND daemon_id='{$daemon_id}'");
    if (!$arrService) {
        halt(SERVER_ERROR);
        return;
    }
    $id = $arrService[0]['id'];
    $result = $db->delete("DELETE FROM {$cfg['tblService']}\n        WHERE id='{$id}'\n        LIMIT 1");
    $resultForeign = $db->delete("DELETE FROM {$cfg['tblAccess']}\n        WHERE dienst_id='{$id}'");
    if (!$result || !$resultForeign) {
        halt(SERVER_ERROR);
        return;
    }
    set('server', array('id' => $server_id));
    set('daemon', array('id' => $daemon_id));
    if (isAjaxRequest()) {
        return js('daemons_servers/delete.js.php', null);
    } else {
        halt(HTTP_NOT_IMPLEMENTED);
    }
}
Example #9
0
function fz_dispatcher()
{
    $controller = 'App_Controller_' . params('controller');
    $controllerInstance = new $controller();
    $controllerInstance->init();
    return call_user_func(array($controllerInstance, params('action') . 'Action'));
}
Example #10
0
/**
 * Change Rank controller.
 *
 * @author paul.michaud
 * @author loic.bothorel
 */
function changeRank()
{
    $promoParam = params('promo');
    $tabPromo = getDistinctPromo();
    set('tabPromo', $tabPromo);
    set('promoParam', $promoParam);
    return render('changeRank.html.php', 'layout/layout.html.php');
}
Example #11
0
function get_author_or_404()
{
    $author = find_author_by_id(filter_var(params('id'), FILTER_VALIDATE_INT));
    if (is_null($author)) {
        halt(NOT_FOUND, "This author doesn't exist.");
    }
    return $author;
}
Example #12
0
function how_are_you()
{
    $name = params('name');
    if (empty($name)) {
        halt(NOT_FOUND, "Undefined name.");
    }
    return html("I hope you are fine, {$name}.");
}
Example #13
0
function get_book_or_404()
{
    $book = find_book_by_id(filter_var(params('id'), FILTER_VALIDATE_INT));
    if (is_null($book)) {
        halt(NOT_FOUND, "This book doesn't exist.");
    }
    return $book;
}
Example #14
0
function extractParams()
{
    global $namespace, $action, $jsonp;
    // ...
    $namespace = params('namespace');
    $basedir = params('basedir');
    $action = params('action');
    $jsonp = params('jsonp');
}
Example #15
0
function get_VkMethod($method_name, $parameters = array())
{
    ksort($parameters);
    $parameters = params($parameters);
    $url = VKAPI_SERVER . $method_name . "?" . $parameters;
    $result = doHttpRequest($url);
    $result = urldecode($result);
    $data = json_decode($result, true);
    return $data["response"];
}
 function get_page($num = false)
 {
     $this->current_page = $num;
     # if num is false, grab from the params
     $num = $num === false ? params($this->page_param) : $num;
     # still might be, so default to zero
     $num = $num ? ($num - 1) * $this->per_page : 0;
     $this->iterator->set_limit($num, $this->per_page);
     return $this->iterator;
 }
Example #17
0
 function image_show_jpeg_only()
 {
   $ext = file_extension(params(0));
   $filename = option('public_dir').params(0);
   if(params('size') == 'thumb') $filename .= ".thb";
   $filename .= '.jpg';
 
   if(!file_exists($filename)) halt(NOT_FOUND, "$filename doesn't exists");
   render_file($filename);
 }
function page_remove_bookmark()
{
    $id = params('id');
    $ok = model_remove($id);
    if ($ok) {
        flash('info', 'Záložka smazána.');
    } else {
        flash('error', 'Záložku se nepodařilo smazat.');
    }
    redirect_to('/');
}
Example #19
0
 static function delete()
 {
     $post = Post::find_by_id(params('id'));
     //only owner
     if ($_SESSION['user']['id'] != $post->user_id) {
         redirect_to('/' . $post->id);
     } else {
         $post->delete();
         redirect_to('/');
     }
 }
function updPromo()
{
    $promo = params("promo");
    $newLabel = params("newLabel");
    $promoToUpd = Promo::getPromoByPromo($promo);
    $promoToUpd->setLabel($newLabel);
    $status = $promoToUpd->update();
    set("status", $status);
    header('Content-Type: application/json');
    return render("status.json.php");
}
Example #21
0
function books()
{
    $o = "lang=" . params('lang');
    if (array_key_exists('sort', $_GET)) {
        $o .= " | sort=" . $_GET['sort'];
    }
    if (array_key_exists('page', $_GET)) {
        $o .= " | page=" . $_GET['page'];
    }
    return $o;
}
Example #22
0
function before($route = array())
{
    #print_r($route); exit;
    #inspect the $route array, looking at various options that may have been passed in
    if (@$route['options']['authenticate']) {
        authenticate_user() or halt("Access denied");
    }
    if (@$route['options']['validation_function']) {
        call_if_exists($route['options']['validation_function'], params()) or halt("Woops! Params did not pass validation");
    }
}
function delData()
{
    $id = params("id");
    if ($id == null) {
        $status = Data::deleteAllDatas();
    } else {
        $status = Data::getDataById($id)->delete();
    }
    set("status", $status);
    header('Content-Type: application/json');
    return render("status.json.php");
}
Example #24
0
 public static function create_or_edit()
 {
     $id = params('id');
     if (empty($id)) {
         $project = new Project();
     } else {
         $project = Project::getById($id);
     }
     $users = dfUser::getAll();
     set('project', $project);
     set('users', $users);
     output('/projects/edit.html.php');
 }
Example #25
0
function ports_delete()
{
    $id = intval(params('id'));
    $cfg = $GLOBALS['cfg'];
    $db = $GLOBALS['db'];
    $result = $db->delete("DELETE FROM {$cfg['tblPort']}\n        WHERE id={$id}\n        LIMIT 1");
    if (!$result) {
        halt(SERVER_ERROR);
        return;
    }
    set('port', array('id' => $id));
    if (isAjaxRequest()) {
        return js('ports/delete.js.php', null);
    } else {
        halt(HTTP_NOT_IMPLEMENTED);
    }
}
Example #26
0
function update_time_left()
{
    global $api;
    $item_id = params('item_id');
    $state = $_POST['state'];
    $data = array(array('value' => $state));
    $api->item->updateFieldValue($item_id, ITEM_STATE_ID, $data);
    // Set time_left to '0' when moving to one of the 'done' states
    if (in_array($state, array(STATE_DEV_DONE, STATE_QA_DONE, STATE_PO_DONE))) {
        $api->item->updateFieldValue($item_id, ITEM_TIMELEFT_ID, array(array('value' => 0)), 1);
    } elseif ($state == STATE_NOT_STARTED) {
        $item = $api->item->getBasic($item_id);
        $item = new ScrumioItem($item);
        $api->item->updateFieldValue($item_id, ITEM_TIMELEFT_ID, array(array('value' => $item->estimate * 60 * 60)), 1);
    }
    return txt('ok');
}
Example #27
0
 /**
  * Action called from the javascript to request file upload progress
  * @return string (json)
  */
 public function getProgressAction()
 {
     $this->secure();
     $uploadId = params('upload_id');
     if (!$uploadId) {
         halt(HTTP_BAD_REQUEST, 'A file id must be specified');
     }
     $progressMonitor = fz_config_get('app', 'progress_monitor');
     $progressMonitor = new $progressMonitor();
     if (!$progressMonitor->isInstalled()) {
         halt(HTTP_NOT_IMPLEMENTED, 'Your system is not configured for' . get_class($progressMonitor));
     }
     $progress = $progressMonitor->getProgress($uploadId);
     if (!is_array($progress)) {
         halt(NOT_FOUND);
     }
     return json($progress);
 }
Example #28
0
function access_delete()
{
    $cfg = $GLOBALS['cfg'];
    $db = $GLOBALS['db'];
    $role_id = intval(params('role_id'));
    $dienst_id = intval(params('service_id'));
    $result = $db->delete("DELETE FROM {$cfg['tblAccess']}\n        WHERE rolle_id='{$role_id}'\n        AND dienst_id='{$dienst_id}'\n        LIMIT 1");
    if (!$result) {
        halt(SERVER_ERROR);
        return;
    }
    set('role', array('id' => $role_id));
    set('service', array('id' => $dienst_id));
    if (isAjaxRequest()) {
        return js('access/delete.js.php', null);
    } else {
        halt(HTTP_NOT_IMPLEMENTED);
    }
}
Example #29
0
 public function run()
 {
     $tipsModel = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_TIPS])->all(), 'content', 'title');
     $tips = array_rand($tipsModel);
     $recommendResources = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_RSOURCES])->all(), 'title', 'url');
     $links = RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_LINKS])->all();
     $sameTopics = [];
     if ($this->node) {
         $sameTopics = ArrayHelper::map(Topic::find()->where('status >= :status', [':status' => Topic::STATUS_ACTIVE])->andWhere(['post_meta_id' => $this->node->id, 'type' => 'topic'])->limit(200)->all(), 'title', function ($e) {
             return Url::to(['/topic/default/view', 'id' => $e->id]);
         });
         if (count($sameTopics) > 10) {
             $sameTopics = Arr::arrayRandomAssoc($sameTopics, 10);
         }
         if ($this->type == 'view' && (in_array($this->node->alias, params('donateNode')) || array_intersect(explode(',', $this->tags), params('donateTag')))) {
             $donate = Donate::findOne(['user_id' => Topic::findOne(['id' => request()->get('id')])->user_id, 'status' => Donate::STATUS_ACTIVE]);
         }
     }
     return $this->render('topicSidebar', ['category' => PostMeta::blogCategory(), 'config' => ['type' => $this->type, 'node' => $this->node], 'sameTopics' => $sameTopics, 'tips' => $tips, 'donate' => isset($donate) ? $donate : [], 'recommendResources' => $recommendResources, 'links' => $links]);
 }
function updates()
{
    header('Content-Type: application/json; charset=utf-8');
    $query_count = params("queries");
    if ($query_count < 1) {
        $query_count = 1;
    }
    if ($query_count > 500) {
        $query_count = 500;
    }
    $worlds = array();
    for ($i = 0; $i < $query_count; $i++) {
        $id = mt_rand(1, 10000);
        $world = World::find($id);
        $world->randomnumber = mt_rand(1, 10000);
        $world->save();
        $worlds[] = $world->to_array();
    }
    return json($worlds);
}