Example #1
0
function acumulus_inject_gateway($vars)
{
    $vars = array_merge($vars, getAddonVars());
    if ($vars['filename'] != 'configgateways') {
        return;
    }
    $api = new api($vars['code'], $vars['username'], $vars['password']);
    $api->setCategory('picklists')->setAction('picklist_accounts');
    $api->execute();
    $response = $api->getResponse();
    if ($api->hasErrors()) {
        $response = array();
        $response['accounts'] = array();
        $response['accounts']['account'] = array();
        $response['accounts']['account'][] = array('accountid' => '', 'accountnumber' => 'API errors', 'accountdescription' => null);
        foreach ($api->getErrors() as $error) {
            $response['accounts']['account'][] = array('accountid' => '', 'accountnumber' => $error['code'], 'accountdescription' => $error['message']);
        }
    }
    $inject = '<script>';
    $gatewayQuery = mysql_query('SELECT name.gateway, acumulus_account.value AS acumulus_account FROM tblpaymentgateways AS name LEFT JOIN tblpaymentgateways AS acumulus_account ON acumulus_account.setting = "acumulusAccount" AND acumulus_account.gateway = name.gateway WHERE name.setting = "name"');
    while ($gatewayFetch = mysql_fetch_assoc($gatewayQuery)) {
        $inject .= '$(\'#Payment-Gateway-Config-' . $gatewayFetch['gateway'] . '\').find(\'tr:last\').before(\'<tr><td class="fieldlabel">Acumulus rekening</td><td class="fieldarea"><select name="field[acumulusAccount]">';
        foreach ($response['accounts']['account'] as $action) {
            $inject .= '<option value="' . $action['accountid'] . '" ' . ($gatewayFetch['acumulus_account'] == $action['accountid'] ? 'selected="selected"' : '') . '>' . $action['accountnumber'] . '' . (is_string($action['accountdescription']) ? ' - ' . $action['accountdescription'] : '') . '</option>';
        }
        $inject .= '</select>Voeg alle facturen met deze betaalmethode toe aan een bepaalde rekening, <a href="https://wiki.acumulus.nl/index.php?page=payment-service-provider" target="_blank">zie hier waarom</a>.</td></tr>\');';
    }
    $inject .= '</script>';
    return $inject;
}
function getChampSquares()
{
    $champSquares = scandir("../img/champs/squares");
    ?>
 <ul class="champ-list mCustomScrollbar" data-mcs-theme="rounded-dots"> <?php 
    $api = new api();
    $champions = json_decode($api->getChampionsList());
    foreach ($champSquares as $key => $square) {
        if ($key > 1) {
            foreach ($champions->data as $champKey => $champion) {
                if ($champion->name == str_replace('.png', '', $square)) {
                    ?>
						<li class="champ-list-element" data-champKey="<?php 
                    print $champion->key;
                    ?>
" onclick="selectChampion(this)" data-name="<?php 
                    print str_replace('.png', '', $square);
                    ?>
"><img src=" <?php 
                    print "/img/champs/squares/" . $square;
                    ?>
 " class="champ-square darkened"></li>
						<?php 
                }
            }
        }
    }
}
Example #3
0
 private function setImageLinks()
 {
     // Load the API for the user.
     $api = new api($this->ID);
     // Set/Get the image.
     if ($api->valid()) {
         $this->smallPicUrl = "<img src=\"https://image.eveonline.com/Character/" . $api->getCharacterID() . "_64.jpg\">";
         $this->largePicUrl = "<img src=\"https://image.eveonline.com/Character/" . $api->getCharacterID() . "_256.jpg\">";
     }
 }
function display_api_results($test_code)
{
    $api = new api();
    $curl_result = $api->connect_api($test_code);
    $i = 0;
    echo "<pre>";
    $size = sizeof($curl_result['report']['completed_test']);
    for ($i; $i < $size; $i++) {
        echo $i + 1 . ". " . $curl_result['report']['completed_test'][$i]['candidate_name'] . " & Score : " . $curl_result['report']['completed_test'][$i]['candidate_total_score'] . "<br>";
    }
}
Example #5
0
function deleteAPIKey()
{
    global $MySelf;
    global $DB;
    if ($MySelf->canManageUser()) {
        numericCheck($_GET[id]);
        $api = new api($_GET[id]);
        $api->deleteApiKey();
        makeNotice("Api key for user " . ucfirst(idToUsername($_GET[id])) . " has been deleted from the database", "notice", "API deleted.", "index.php?action=edituser&id=" . $_GET[id], "[OK]");
    }
    makeNotice("You do not have permission to modify users.", "warning", "Access denied.");
}
Example #6
0
 /**
  * Methode zum anzeigen des Contents.
  *
  * @return String Content der Applikation.
  */
 public function display()
 {
     $view = new View();
     switch ($this->template) {
         case 'createTables':
             $view->setTemplate('createTables');
             $oApi = new api();
             $aResult = $oApi->createDatabase();
             $view->assign('state', $aResult);
             break;
         case 'config':
             $view->setTemplate('config');
             if (!empty($this->sleep)) {
                 Model::setConfigSleepData($this->sleep);
             }
             $aConfigData = Model::getConfigSleepData();
             $view->assign('config', $aConfigData);
             break;
         case 'report':
             $view->setTemplate('report');
             $view->assign('state', $this->state);
             $aReportData = Model::getReportData();
             $view->assign('data', $aReportData);
             if (!empty($this->request['a'])) {
                 switch ($this->request['a']) {
                     case 1:
                         break;
                     case 2:
                         $view->assign('users', Model::getUser());
                         if ($this->user) {
                             $view->assign('reportDataByUser', Model::getReportDataByParams('reportUsers', $this->user));
                         } else {
                             $view->assign('reportDataByUser', Model::getReportDataByParams('reportUsers', '%%'));
                         }
                         break;
                     case 3:
                         $view->assign('reportDataApps', Model::getReportDataByApps());
                         break;
                     case 4:
                         $view->assign('reportDataMac', Model::getReportDataByParams('reportMac', '%%'));
                         break;
                     default:
                 }
             }
             break;
         default:
             $view->setTemplate('start');
     }
     return $view->loadTemplate();
 }
Example #7
0
 public function sort($id = '')
 {
     $page = $this->page($id);
     $blueprint = blueprint::find($page);
     $uids = get('uids');
     $flip = $blueprint->pages()->sort() == 'flip';
     $children = $page->children();
     if ($flip) {
         $index = get('index', 1);
         $uids = array_reverse($uids);
         $n = $page->children()->visible()->count() - ($index * $blueprint->pages()->limit() - 1);
         if ($n <= 0) {
             $n = 1;
         }
     } else {
         $index = get('index', 1) - 1;
         $n = $blueprint->pages()->limit() * $index + 1;
     }
     foreach ($uids as $uid) {
         try {
             $child = $children->find($uid);
             $x = api::createPageNum($child, $blueprint);
             if ($x !== false and $x >= 0) {
                 $child->sort($x);
             } else {
                 $child->sort($n);
             }
             $n++;
         } catch (Exception $e) {
         }
     }
     return response::success('success');
 }
Example #8
0
 public function add($id = '/')
 {
     $page = $this->page($id);
     $blueprint = blueprint::find($page);
     $templates = $blueprint->pages()->template();
     $options = array();
     $back = array('subpages' => purl('subpages/index/' . $page->id()), 'page' => purl($page, 'show'));
     $form = app::form('pages.add');
     $form->save = l('add');
     $form->back = a::get($back, get('to'));
     foreach ($templates as $template) {
         $options[$template->name()] = $template->title();
     }
     $select = form::field('select', array('name' => 'template', 'label' => l('pages.add.template.label'), 'options' => $options, 'required' => true));
     if ($templates->count() == 1) {
         $select->readonly = true;
         $select->value = $templates->first()->name();
     }
     $form->fields()->append('template', $select);
     if (api::maxPages($page, $blueprint->pages()->max())) {
         $form->fields = array('info' => form::field('info', array('label' => 'pages.add.error.max.headline', 'text' => 'pages.add.error.max.text')));
         $form->save = false;
         $form->centered = true;
     }
     return view('pages/add', array('page' => $page, 'form' => $form));
 }
Example #9
0
 /**
  * 获取群列表
  */
 public function index()
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } else {
         $data = $this->get_data();
         $type = (int) $this->input->get('type', 0);
         $result = $this->model->getUserAllGroup($this->user_id, $type);
         $showTabList = Tab_Model::instance()->getList($this->user_id, 1);
         $gidList = array();
         foreach ($showTabList as $key => $value) {
             if ($value['id'] != Kohana::config('uap.xiaomo_qun')) {
                 $gidList[$value['id']] = $key;
             }
         }
         $groupList = array();
         $privateType = Kohana::config('group.type.private');
         foreach ($result as $value) {
             $sort = (int) $gidList[$value['gid']];
             $groupInfo = array();
             $groupInfo['is_hide'] = 0;
             if (array_key_exists($value['gid'], $gidList)) {
                 $groupInfo['is_hide'] = 0;
             }
             $groupInfo['id'] = floatval($value['gid']);
             $groupInfo['name'] = $value['gname'];
             $groupInfo['notice'] = $value['notice'];
             $groupInfo['introduction'] = $value['introduction'];
             $groupInfo['privacy'] = intval($value['privacy']);
             $groupInfo['created_at'] = api::get_date($value['create_time']);
             $groupInfo['modified_at'] = api::get_date($value['modify_time']);
             $creator = array();
             $creator['id'] = floatval($value['creator_id']);
             $creator['name'] = sns::getrealname($value['creator_id']);
             $creator['avatar'] = sns::getavatar($value['creator_id']);
             $groupInfo['creator'] = $creator;
             $groupInfo['master'] = $creator;
             $managerIdList = $this->model->getManagerId($groupInfo['id']);
             $managerList = array();
             foreach ($managerIdList as $val) {
                 $manager = array();
                 $manager['id'] = floatval($val['uid']);
                 $manager['name'] = sns::getrealname($manager['id']);
                 $manager['avatar'] = sns::getavatar($manager['id']);
                 $managerList[] = $manager;
                 unset($manager);
             }
             $groupInfo['manager'] = $managerList;
             $groupInfo['member_count'] = (int) $this->model->getGroupMemberNum($value['gid']);
             $groupList[$sort] = $groupInfo;
             unset($groupInfo);
             unset($creator);
         }
         ksort($groupList);
         foreach ($groupList as $group) {
             $return_list[] = $group;
         }
         $this->send_response(200, $return_list);
     }
 }
Example #10
0
 public function index()
 {
     $users = $this->users()->map(function ($user) {
         return api::user($user);
     });
     return response::json(array_values($users->toArray()));
 }
Example #11
0
 public function show($id = null)
 {
     $filename = get('filename');
     $page = $this->page($id);
     $file = $this->file($page, $filename);
     $blueprint = blueprint::find($page);
     $fields = $blueprint->files()->fields($page);
     $meta = $file->meta()->toArray();
     $files = api::files($page, $blueprint);
     $index = $files->indexOf($file);
     $next = $files->nth($index + 1);
     $prev = $files->nth($index - 1);
     // breadcrumb items
     if ($page->isSite()) {
         $items = array(array('url' => purl('metatags'), 'title' => l('metatags')), array('url' => purl('files/index'), 'title' => l('metatags.files')), array('url' => purl($file, 'show'), 'title' => $file->filename()));
     } else {
         $items = array(array('url' => purl('files/index/' . $page->id()), 'title' => l('files')), array('url' => purl($file, 'show'), 'title' => $file->filename()));
     }
     // file info display
     $info = array();
     $info[] = $file->type();
     $info[] = $file->niceSize();
     if ((string) $file->dimensions() != '0 x 0') {
         $info[] = $file->dimensions();
     }
     return view('files/show', array('topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => $items)), 'search' => purl($page, 'search'))), 'form' => new Form($fields->toArray(), $meta), 'p' => $page, 'f' => $file, 'next' => $next, 'prev' => $prev, 'info' => implode(' / ', $info)));
 }
Example #12
0
 public function __construct($request)
 {
     parent::__construct($request);
     $this->{$dbh} = new PDO("mysql:host=" . self::DB_CONFIG_HOST . ";dbname=" . self::DB_CONFIG_NAME . ";charset=" . self::DB_CONFIG_ENCD, self::DB_CONFIG_USER, self::DB_CONFIG_PASS);
     $this->{$dbh}->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     if (!$this - $dbh) {
         throw new Exception('Error while establishing database connection!');
     }
 }
Example #13
0
 public static function getAllBranch()
 {
     $api = new api();
     $ss = $api->getSsName();
     $all_branch = [];
     $all_ss = [];
     $ss_address = [];
     $ss_tel = [];
     foreach ($ss as $k => $v) {
         $all_branch[$v['branch_code']] = $v['branch_name'];
         $all_ss[$v['sscode']] = $v['ss_name'];
         $all_ss_branch[$v['sscode']] = $v['branch_code'];
         $all_branch_ss[$v['branch_code']][] = $v['sscode'];
         $ss_address[$v['sscode']] = $v['address'];
         $ss_tel[$v['sscode']] = $v['tel'];
     }
     return ['all_ss' => $all_ss, 'all_branch' => \Yii::$app->params['branch'], 'all_branch_ss' => $all_branch_ss, 'all_ss_branch' => $all_ss_branch, 'ss_address' => $ss_address, 'ss_tel' => $ss_tel];
 }
Example #14
0
 public static function rm($data, $id, $token)
 {
     $r = new stdClass();
     $r->code = 1004;
     // record could not be removed
     if (parent::_rm($data, "currency")) {
         $r->code = 0;
     }
     return $r;
 }
Example #15
0
 public function login_action()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (empty($_POST['email']) || empty($_POST['password']) || !account::log_in($_POST['email'], $_POST['password'])) {
             return api::result(false);
         }
         return api::result(true);
     }
     return api::result(false);
 }
 /**
  * Loads the data for the key provided ready formatted for caching.
  *
  * @param string|int $key The key to load.
  * @return mixed What ever data should be returned, or false if it can't be loaded.
  */
 public function load_for_cache($key)
 {
     list($userid1, $userid2) = explode('_', $key);
     $message = api::get_most_recent_message($userid1, $userid2);
     if ($message) {
         return $message->timecreated;
     } else {
         return null;
     }
 }
Example #17
0
 public function formatted_action($key)
 {
     if (empty($key)) {
         return api::result(false, array('message' => 'No_key_provided'));
     }
     $kb = knowledge_base_article::load_one($key, 'key');
     if (!$kb) {
         return api::result(false, array('message' => 'Article_not_found'));
     }
     return api::result(true, array('formatted' => addslashes($kb->formatted())));
 }
Example #18
0
 public function rest()
 {
     $api = api::get();
     $args = func_get_args();
     // Normal request
     if (!$api) {
         print_r($args);
     } else {
         echo json_encode($args, TRUE);
     }
 }
Example #19
0
 /**
  * 
  * @param $title
  * @param $description
  * @param $price
  * @param $sync
  * @param $private
  * @param $image
  * @param $location
  * @return unknown_type
  */
 public function create($title, $description, $price, $private, $image, $location, $user_id, $sync)
 {
     $deal_id = api::uuid();
     $setters = array('deal_id' => $deal_id, 'uid' => $user_id, 'longitude' => $location['longitude'] ? $location['longitude'] : 0, 'latitude' => $location['latitude'] ? $location['latitude'] : 0, 'price' => $price, 'private' => $private, 'created_at' => time(), 'modified_at' => time());
     if ($this->db->insertData('deals', $setters)) {
         $image = $this->_warp_image($image);
         if ($this->_insert_mongo(array('deal_id' => $deal_id, 'uid' => $user_id, 'title' => $title, 'description' => $description, 'image' => $image, 'sync' => $sync))) {
             return true;
         }
     }
     return false;
 }
Example #20
0
 public function index()
 {
     $site = site();
     $blueprint = blueprint::find($site);
     $fields = $blueprint->fields($site)->toArray();
     $content = $site->content()->toArray();
     $files = null;
     // create the files
     if ($blueprint->files()->max() !== 0 and $blueprint->files()->hide() == false) {
         $files = new Snippet('pages/sidebar/files', array('page' => $site, 'files' => api::files($site, $blueprint)));
     }
     return view('metatags/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb', array('items' => array(array('title' => l('metatags'), 'url' => purl('metatags/'))))), 'search' => purl('pages/search/'))), 'form' => new Form($fields, $content), 's' => $site, 'files' => $files, 'license' => panel()->license()));
 }
 /**
  * Funcion: getFunction   
  * Descripcion: Dirige la peticion a la funcion correspondiente
  * @param api $api
  * @return $salida
  * @throws Exception
  * @author Rodrigo Contreras B. <*****@*****.**>
  * @version 2015-12-07 - Version Inicial
  * @version 2015-12-29 - Simplificacion metodo de llamados
  * @since 2015-12-07
  */
 function getFunction(api $api)
 {
     // Variables Generales
     $request = $this->setRequest();
     $withRequest = 0;
     // Librerias
     $controller = $api->getController();
     $controllerBusiness = $api->getController() . 'Business';
     // Crea objeto si existe la clase
     if (!class_exists($controllerBusiness)) {
         $api->setTipo("Error");
         $api->setMensaje("No existe el Controlador Asociado");
         $salida = $api;
     } else {
         // Creacion del Objeto Business correspondiente
         $objBusiness = new $controllerBusiness();
         // Creacion del objeto controlador
         if (file_exists('../model/' . $controller . '.php')) {
             $obj = new $controller();
         }
         // Verificacion de existencia business
         if (file_exists('../business/' . $controller . 'Business.php')) {
             // Identificacion de funcion requestToObjeto
             $req = 'requestTo' . $controller;
             // Verificacion de existencia de metodo dentro de clase
             if (method_exists($objBusiness, $req)) {
                 $obj = $objBusiness->{$req}($request);
                 $withRequest = 1;
             }
         }
         // Identificacion Metodo
         $metodo = $api->getAccion();
         if (!method_exists($objBusiness, $metodo)) {
             $api->setTipo("Error");
             $api->setMensaje("No existe el Metodo Asociado");
             $salida = $api;
         } else {
             // Llamado a metodo para salida de datos
             if ($withRequest == 1) {
                 $salida = $objBusiness->{$metodo}($obj);
             } else {
                 $salida = $objBusiness->{$metodo}();
             }
         }
     }
     // Retorno
     return $salida;
 }
Example #22
0
function initAPI()
{
    global $mods;
    global $core;
    /** Variables */
    $started = session_start();
    $uid = session_id();
    $received = $_REQUEST;
    $expecting = ['class', 'method', 'type', 'data'];
    /** Include API Class and Change to System */
    include 'api.php';
    chdir("../../system");
    /** Loop through the expected input, ignoring others to set varNames*/
    foreach ($expecting as $varName) {
        ${$varName} = isset($received[$varName]) ? $received[$varName] : ($varName == 'data' ? [] : null);
    }
    /** Create an API Request Object for Input */
    $request = new apiRequest($class, $method, $type, $data);
    $api = new api();
    /** Boot Framework */
    $booted = (include 'bootstrap/bootstrap.php');
    if (!$booted) {
        throw new exception("Boot Manager Missing!");
        exit;
    }
    $plugableLibraries = [];
    boot(new bootMode('api'), $plugableLibraries);
    /** Create New API Core */
    $core = new core($api, $plugableLibraries, $mods);
    /** Add Request to Queue */
    $requestId = $api->addRequest($request);
    /** Process API Request */
    $results = $core->processRequests();
    $apiResult = $results[$requestId];
    /** Encode Result */
    $jsonResult = json_encode($apiResult);
    return $jsonResult;
}
Example #23
0
 public function show($id)
 {
     $filename = get('filename');
     $page = $this->page($id);
     $file = $this->file($page, $filename);
     $blueprint = blueprint::find($page);
     $fields = $blueprint->files()->fields($page);
     $meta = $file->meta()->toArray();
     $files = api::files($page, $blueprint);
     $index = $files->indexOf($file);
     $next = $files->nth($index + 1);
     $prev = $files->nth($index - 1);
     return view('files/show', array('topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => array(array('url' => purl('files/index/' . $page->id()), 'title' => l('files')), array('url' => purl($file, 'show'), 'title' => $file->filename())))), 'search' => purl($page, 'search'))), 'form' => new Form($fields->toArray(), $meta), 'p' => $page, 'f' => $file, 'next' => $next, 'prev' => $prev));
 }
Example #24
0
 public function __construct($request, $origin)
 {
     parent::__construct($request);
     // Abstracted out for example
     //$APIKey = new authaccess();//new Models\APIKey();
     // if (!array_key_exists('apiKey', $this->input)) {
     //     throw new Exception('No API Key provided');
     // } else if (!$APIKey->verifyKey($this->input->apiKey, $origin)) {
     //     throw new Exception('Invalid API Key');
     // } else if (array_key_exists('token', $this->input) &&
     //      !$User->get('token', $this->input->token)) {
     //     throw new Exception('Invalid User Token');
     // }
     // $this->User = $User;
 }
Example #25
0
 /**
  * Generate field content markup
  *
  * @return string
  */
 public function content()
 {
     $wrapper = new Brick('div');
     $wrapper->addClass('subpagelist');
     $children = $this->subpages();
     // add pagination to the subpages
     $limit = $this->limit() ? $this->limit() : 10000;
     $children = $children->paginate($limit, array('page' => get('page')));
     // use existing snippet to build the list
     // @see panel/app/controllers/views/pages.php
     $subpages = new Snippet('pages/sidebar/subpages', array('title' => l('pages.show.subpages.title'), 'page' => $this->page(), 'subpages' => $children, 'addbutton' => !api::maxPages($this, $this->subpages()->max()), 'pagination' => $children->pagination()));
     // use template with defined vars
     $wrapper->html(tpl::load(__DIR__ . DS . 'template.php', array('subpages' => $subpages)));
     return $wrapper;
 }
 public function index()
 {
     $site = site();
     $widgets = array();
     $wroot = kirby()->roots()->widgets();
     $wdirs = dir::read($wroot);
     // fetch all top-level pages in the right order
     $blueprint = blueprint::find($site);
     $pages = api::subpages($site->children(), $blueprint);
     foreach ($wdirs as $dir) {
         $file = $wroot . DS . $dir . DS . $dir . '.php';
         if (file_exists($file)) {
             $widgets[$dir] = (require $file);
         }
     }
     return view('dashboard/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb'), 'search' => purl('pages/search/'))), 'history' => history::get(), 'site' => $site, 'pages' => $pages, 'addbutton' => !api::maxPages($site, $blueprint->pages()->max()), 'widgets' => $widgets, 'user' => site()->user(), 'license' => panel()->license()));
 }
Example #27
0
 public function execute($message)
 {
     global $pluginManager;
     global $t;
     $t->setPlugin("netutils");
     $reply = "";
     $data = $message->getData();
     $shell = new Shell();
     $execute = true;
     $call = $message->getCommand();
     array_shift($data);
     switch ($call) {
         case "nslookup":
             $shell->setFilter(array("main" => "nslookup", "subarg" => array()));
             $cmd = "nslookup " . implode(" ", $data);
             break;
         case "dig":
             $shell->setFilter(array("main" => "dig", "subarg" => array()));
             $cmd = "dig " . implode(" ", $data);
             break;
         case "nmap":
             $shell->setFilter(array("main" => "nmap", "subarg" => array()));
             $cmd = "nmap " . implode(" ", $data);
             break;
         case "whois":
             $shell->setFilter(array("main" => "whois", "subarg" => array()));
             $cmd = "whois " . implode(" ", $data);
             break;
         default:
             $reply = $t->g("default");
             $execute = false;
             break;
     }
     if ($execute) {
         $shell->setCmd($cmd);
         if ($shell->execute()) {
             $reply = "`\$ " . api::encodePlain($cmd) . "\n" . api::encodePlain(implode("\n", $shell->getOutput())) . "`";
         } else {
             $reply = sprintf($t->g("command_error"), api::encodePlain($cmd));
         }
     }
     // Api::reply($message, $reply, true);
     global $api;
     $api->sendMessage($message->chat->id, $reply, "Markdown", true);
 }
Example #28
0
 public function update($id = '')
 {
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('pages.error.missing'));
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->fields($page);
     $oldTitle = (string) $page->title();
     // trigger the validation
     $form = new Form($fields->toArray());
     $form->validate();
     // fetch the data for the form
     $data = pagedata::createByInput($page, $form->serialize());
     // stop at invalid fields
     if (!$form->isValid()) {
         return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
     }
     try {
         PageStore::discard($page);
         $page->update($data);
         // make sure that the sorting number is correct
         if ($page->isVisible()) {
             $num = api::createPageNum($page);
             if ($num !== $page->num()) {
                 if ($num > 0) {
                     $page->sort($num);
                 }
             }
         }
         // get the blueprint of the parent page to find the
         // correct sorting mode for this page
         $parentBlueprint = blueprint::find($page->parent());
         // auto-update the uid if the sorting mode is set to zero
         if ($parentBlueprint->pages()->num()->mode() == 'zero') {
             $uid = str::slug($page->title());
             $page->move($uid);
         }
         history::visit($page->id());
         kirby()->trigger('panel.page.update', $page);
         return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id()));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
Example #29
0
function ShowNews($template_news = NULL, $params = NULL, $args)
{
    $api_news = new api(APPLICATION_NAME);
    # подключаем шаблон кратких новостей -> news_min.tpl
    if ($template_news == NULL) {
        $news_min_template = $api_news->get_file("news_min.tpl");
    } else {
        $news_min_template = $api_news->get_file($template_news);
    }
    # поиск тегов {date...}
    //preg_match_all('#{date\s*(=\s*\"(s||m||h||d||w||auto)\")?}#is', $news_min_template, $arr_date);
    //FunctionPublic::Pre($arr_date);
    # Достаём из таблицы новости
    //$news = DB::select(PREFIX_."news", $params);
    $news = DB::run("SELECT * FROM " . PREFIX_ . "news " . $params, $args)->fetchAll(PDO::FETCH_ASSOC);
    //FunctionPublic::Pre($params);
    $news_min_all = "";
    $result = "";
    if ($news) {
        // если есть хоть одна новость
        # перебираем все новости и заносим в переменную
        foreach ($news as $value) {
            $date = unserialize($value["time"]);
            //$time_news = FunctionPublic::getTime($date["time"], "s");
            $result = $api_news->set_new_tpl("{title}", $value["title"], $news_min_template);
            $result = $api_news->set_new_tpl("{news_link}", $value["url"] . ".html", $result);
            $result = $api_news->set_new_tpl("{news_min}", $value["news_min"], $result);
            $result = $api_news->set_new_tpl("{category_link}", "{HOME}" . $value["cat_url"], $result);
            $result = $api_news->set_new_tpl("{category_name}", $value["cat_name"], $result);
            $result = $api_news->set_new_tpl("{date}", $date["date"], $result);
            $news_min_all .= $result;
        }
        unset($news);
        unset($value);
    }
    return $news_min_all;
}
Example #30
0
 public function index($id = null)
 {
     $page = $this->page($id);
     $blueprint = blueprint::find($page);
     $visible = api::subpages($page->children()->visible(), $blueprint);
     $invisible = api::subpages($page->children()->invisible(), $blueprint);
     $baseUrl = rtrim(purl('subpages/index/' . $page->id()), '/');
     // don't create the view if the page is not allowed to have subpages
     if ($blueprint->pages()->max() === 0) {
         goToErrorView();
     }
     if ($limit = $blueprint->pages()->limit()) {
         $visible = $visible->paginate($limit, array('page' => get('visible')));
         $invisible = $invisible->paginate($limit, array('page' => get('invisible')));
         $visiblePagination = new Snippet('subpages/pagination', array('pagination' => $visible->pagination(), 'nextUrl' => $baseUrl . '/visible:' . $visible->pagination()->nextPage() . '/invisible:' . $invisible->pagination()->page(), 'prevUrl' => $baseUrl . '/visible:' . $visible->pagination()->prevPage() . '/invisible:' . $invisible->pagination()->page()));
         $invisiblePagination = new Snippet('subpages/pagination', array('pagination' => $invisible->pagination(), 'nextUrl' => $baseUrl . '/visible:' . $visible->pagination()->page() . '/invisible:' . $invisible->pagination()->nextPage(), 'prevUrl' => $baseUrl . '/visible:' . $visible->pagination()->page() . '/invisible:' . $invisible->pagination()->prevPage()));
     }
     return view('subpages/index', array('page' => $page, 'topbar' => new Snippet('pages/topbar', array('menu' => new Snippet('menu'), 'breadcrumb' => new Snippet('pages/breadcrumb', array('page' => $page, 'items' => array(array('url' => purl('subpages/index/' . $id), 'title' => l('subpages'))))), 'search' => purl($page, 'search'))), 'baseurl' => $baseUrl, 'addbutton' => !api::maxPages($page, $blueprint->pages()->max()) and $page->hasChildren(), 'sortable' => $blueprint->pages()->sortable(), 'visible' => $visible, 'flip' => $blueprint->pages()->sort() == 'flip', 'visiblePagination' => $visiblePagination, 'invisible' => $invisible, 'invisiblePagination' => $invisiblePagination));
 }