Exemplo n.º 1
0
 public function entry($data)
 {
     if (isset($data->_fieldset)) {
         $fieldsetName = $data->_fieldset;
     } else {
         return "No fieldset found in entry.";
     }
     if (isset($this->fieldsets[$fieldsetName])) {
         $fieldset = $this->fieldset($fieldsetName);
         $this->snippet = $fieldset->snippet();
         $this->entry = $fieldset->entry();
         $this->fields = $fieldset->fields();
     } else {
         return 'No fieldset with name "' . $fieldsetName . '" found.';
     }
     $data->_fileUrl = $this->page->contentUrl() . DS;
     if ($this->snippet) {
         $data = structure((array) $data, $this->page());
         return tpl::load(c::get('buildersnippets.path', kirby()->roots()->snippets()) . DS . $this->snippet . '.php', array('page' => $this->page(), 'data' => $data));
     } else {
         return parent::entry($data);
     }
 }
Exemplo n.º 2
0
field::$methods['int'] = function ($field, $default = 0) {
    $val = $field->empty() ? $default : $field->value;
    return intval($val);
};
/**
 * Get a float value for the Field
 * @param Field $field The calling Kirby Field instance
 * @param int $default Default value returned if field is empty
 * @return float
 */
field::$methods['float'] = function ($field, $default = 0) {
    $val = $field->empty() ? $default : $field->value;
    return floatval($val);
};
field::$methods['toStructure'] = field::$methods['structure'] = function ($field) {
    return structure($field->yaml(), $field->page());
};
field::$methods['link'] = function ($field, $attr1 = array(), $attr2 = array()) {
    $a = new Brick('a', $field->value());
    if (is_string($attr1)) {
        $a->attr('href', url($attr1));
        $a->attr($attr2);
    } else {
        $a->attr('href', $field->page()->url());
        $a->attr($attr1);
    }
    return $a;
};
field::$methods['toUrl'] = field::$methods['url'] = function ($field) {
    return url($field->value());
};
Exemplo n.º 3
0
function processAdminRequest($url)
{
    global $modulesMgr, $structureMgr, $authenticationMgr, $permissionsMgr, $cacheMgr, $templatesMgr;
    $userID = $authenticationMgr->getUserID();
    $userGroupID = $authenticationMgr->getUserGroup();
    // Если пользователь - гость, то отправить логиниться
    if ($userID == 1 || $userGroupID != 5) {
        header('Status: 302 Moved');
        header('Location: /login');
        exit;
    }
    SetCfg('InAdmin', true);
    //$pageID = isset($_GET['pageID']) ? $_GET['pageID'] : -1;
    if ($url == '/') {
        $pageID = -1;
    } else {
        //direct link is provided to edit some content
        $pageID = $structureMgr->getPageIDByPath($url);
        //$md = $structureMgr->getMetaData($pageID);
        if (!$pageID) {
            trigger_error('Admin 404 will be provided later. But now it is just a fatal error.', PM_FATAL);
        }
        if (!$permissionsMgr->canUpdate($pageID, $userID)) {
            trigger_error('Beautiful 403 will be provided later. But now it is just a fatal error.', PM_FATAL);
        }
    }
    include '_kernel.edit.php';
    $tpl = $templatesMgr->getTemplate(-1, GetCfg('TemplatesPath') . '/admin/page.html');
    $tpl = str_replace('%site_name%', GetCfg('SiteName'), $tpl);
    $res = '';
    $cmd = _var('cmd');
    if ($pageID == -1) {
        $pageID = _var('pageID');
        if (!$pageID) {
            $pageID = $structureMgr->getRootPageID();
        }
        //print 'pageID='.$pageID;
        if ($permissionsMgr->canUpdate($pageID, $userID) == false) {
            trigger_error('Beautiful 403 will be provided later. But now it is just a fatal error.', PM_FATAL);
        }
        if (!$cmd) {
            $res .= navi($pageID, false);
            $res .= structure($pageID);
            // this very evil function. Very slowed.
        } else {
            $res .= processAdminCommand($cmd, $pageID);
        }
    } else {
        if ($permissionsMgr->canUpdate($pageID, $userID) == false) {
            trigger_error('Beautiful 403 will be provided later. But now it is just a fatal error.', PM_FATAL);
        }
        $res .= processAdminCommand('editPage', $pageID);
    }
    $admMenu = admMenu($cmd);
    $tpl = str_replace('%content%', $res, $tpl);
    $tpl = str_replace('%adm_menu%', $admMenu, $tpl);
    print $tpl;
}
Exemplo n.º 4
0
/**
 * Give this any kind of array
 * to get some kirby style structure
 *
 * @param mixed $data
 * @param mixed $page
 * @param mixed $key
 * @return mixed
 */
function structure($data, $page = null, $key = null)
{
    if (is_null($page)) {
        $page = page();
    }
    if (is_array($data)) {
        $result = new Structure();
        $result->page = $page;
        foreach ($data as $key => $value) {
            $result->append($key, structure($value, $page, $key));
        }
        return $result;
    } else {
        if (is_a($data, 'Field')) {
            return $data;
        } else {
            return new Field($page, $key, $data);
        }
    }
}