当前位置: 首页>>代码示例>>PHP>>正文


PHP needRole函数代码示例

本文整理汇总了PHP中needRole函数的典型用法代码示例。如果您正苦于以下问题:PHP needRole函数的具体用法?PHP needRole怎么用?PHP needRole使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了needRole函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(RDR_User::ROLE_ADMIN, true);
     $this->user = new RDR_User(db());
     if (get("id")) {
         $tmp = RDR_User::getById(get("id"));
         if ($tmp) {
             $this->user = $tmp;
         }
     }
     $this->form = $this->getForm();
     if (post("save")) {
         if (!$this->form->validateAllFields()) {
             v("message", t("form.validation.error"));
         } elseif (post("password") && post("password") != post("password2")) {
             v("message", t("admin.user.2"));
         } else {
             $this->form->setObjectMembersBySubmittedValues($this->user);
             if (post("password")) {
                 $this->user->setPassword(post("password"));
             }
             $this->user->store();
             v("message", t("saved"));
             $this->form = $this->getForm();
         }
     }
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:31,代码来源:User.class.php

示例2: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!needRole()) {
         return;
     }
     if (get("type") == "image") {
         $url = urldecode(get("url"));
         if (substr($url, 0, 2) == "//") {
             $url = "http:" . $url;
         }
         $exp = explode(".", preg_replace("~\\?.*~i", "", $url));
         $extension = end($exp);
         if (count($exp) <= 1 || !$extension || strlen($extension) > 4 || preg_match("~[^a-z]~i", $extension)) {
             $extension = "jpg";
         }
         $slug = md5($url);
         $tmpPath = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/filecontents.{$slug}.{$extension}";
         if (!file_exists($tmpPath)) {
             $data = @file_get_contents($url);
             file_put_contents($tmpPath, $data !== false ? $data : "");
         }
         header("content-type: image/{$extension}");
         header("content-length: " . filesize($tmpPath));
         header("Last-Modified: " . date("r", filemtime($tmpPath)));
         header("Expires: " . date("r", filemtime($tmpPath) + self::CACHETIME));
         header("Cache-Control: public, max-age= " . self::CACHETIME);
         readfile($tmpPath);
     }
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:32,代码来源:Proxy.class.php

示例3: changePassword

 public function changePassword()
 {
     needRole('admin');
     if (!$this->checkPassword(getRole('admin'), $_REQUEST['oldpasswd'])) {
         $this->_tpl->assign('msg', '原密码不对!');
     } else {
         daocall('admin_user', 'updatePassword', array(getRole('admin'), $_REQUEST['passwd']));
         $this->_tpl->assign('msg', '修改密码成功');
     }
     return $this->_tpl->display('msg.html');
 }
开发者ID:srdc2014,项目名称:vhms,代码行数:11,代码来源:session.ctl.php

示例4: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(null, true);
     if (post("savepw")) {
         if (post("newpw") && post("newpw") == post("newpw2")) {
             user()->setPassword(post("newpw"));
             user()->store();
             v("message", t("saved"));
         }
     }
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:15,代码来源:Settings.class.php

示例5: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(RDR_User::ROLE_ADMIN, true);
     if (req()->isAjax()) {
         if (post("update")) {
             $feed = RDR_Feed::getById(post("update"));
             if ($feed) {
                 RDR_Import::importFeedEntries($feed);
             }
         }
         return;
     }
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:17,代码来源:System.class.php

示例6: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(RDR_User::ROLE_ADMIN, true);
     $this->form = $this->getForm();
     if (post("save")) {
         foreach ($this->form->fields as $field) {
             if ($field->attr->get("data-setting")) {
                 RDR_Setting::set($field->name, $field->getSubmittedValue());
             }
         }
         v("message", t("saved"));
         $this->form = $this->getForm();
     }
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:18,代码来源:Settings.class.php

示例7: needRole

<?php

needRole('user');
class FrameControl extends Control
{
    public function __construct()
    {
        parent::__construct();
    }
    public function __destruct()
    {
        parent::__destruct();
    }
    public function login()
    {
        return $this->display('user/index.html');
    }
    public function index()
    {
        $request = '';
        foreach ($_REQUEST as $k => $v) {
            if ($k == 'a' || $k == 'c' || $k == 'fa' || $k == 'fc') {
                continue;
            }
            $request .= '&' . $k . '=' . urlencode($v);
        }
        $this->assign('request', $request);
        return $this->display('frame/index.html');
    }
    public function top()
    {
开发者ID:srdc2014,项目名称:vhms,代码行数:31,代码来源:frame.ctl.php

示例8: needRole

<?php

needRole('admin');
class NodesControl extends Control
{
    public function __construct()
    {
        parent::__construct();
    }
    public function __destruct()
    {
        parent::__destruct();
    }
    public function listNode()
    {
        $username = $_GET['username'];
        $list = daocall('nodes', "listNodes", null);
        $sum = count($list);
        $this->_tpl->assign('sum', $sum);
        $this->_tpl->assign('username', $username);
        $this->_tpl->assign('list', $list);
        $this->_tpl->display('nodes/listnode.html');
    }
    public function addNode()
    {
        $this->_tpl->assign('action', 'insert');
        $this->_tpl->display('nodes/addnode.html');
    }
    public function ajaxCheckNode()
    {
        $node = $_REQUEST['node'];
开发者ID:srdc2014,项目名称:vhms,代码行数:31,代码来源:nodes.ctl.php

示例9: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(null, true);
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:8,代码来源:BrowserScript.class.php

示例10: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     needRole(null, true);
     # OPML
     if (get("opml")) {
         $categories = user()->getCategories();
         $opml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><opml></opml>');
         $opml->addAttribute("version", "1.0");
         $head = $opml->addChild("head");
         $head->addChild("title", "Subscriptions from nReeda");
         $body = $opml->addChild("body");
         foreach ($categories as $category) {
             $cat = $body->addChild("outline");
             $cat->addAttribute("title", $category->name);
             $cat->addAttribute("text", $category->name);
             $feeds = $category->feeds;
             if ($feeds) {
                 foreach ($feeds as $feed) {
                     $f = $cat->addChild("outline");
                     $f->addAttribute("type", "rss");
                     $f->addAttribute("text", $feed->getCustomName($category));
                     $f->addAttribute("title", $feed->getCustomName($category));
                     $f->addAttribute("xmlUrl", $feed->url);
                 }
             }
         }
         $data = $opml->asXML();
         CHOQ_OutputManager::cleanAllBuffers();
         header("Content-type: application/octet-stream");
         header("Content-Disposition: filename=\"nreeda.opml\"");
         echo $data;
         die;
     }
     # textfile
     if (get("file")) {
         $categories = user()->getCategories();
         $lines = array();
         foreach ($categories as $category) {
             $feeds = $category->feeds;
             if ($feeds) {
                 foreach ($feeds as $feed) {
                     $lines[] = $feed->url;
                 }
             }
         }
         $data = implode("\n", $lines);
         CHOQ_OutputManager::cleanAllBuffers();
         header("Content-type: application/octet-stream");
         header("Content-Disposition: filename=\"nreeda.txt\"");
         echo $data;
         die;
     }
     # Import
     if (isset($_FILES["file"]["tmp_name"])) {
         $data = file_get_contents($_FILES["file"]["tmp_name"]);
         if (strpos($data, "<?xml") === false || strpos($data, "</opml>") === false) {
             $event = RDR_Import::importFromFile($_FILES["file"]["tmp_name"]);
             if ($event->type == RDR_Event::TYPE_FILE_OK) {
                 RDR_Import::updateAllFeeds();
             }
             v("message", $event->getText());
         } else {
             $event = RDR_Import::importFromOPML($_FILES["file"]["tmp_name"]);
             if ($event->type == RDR_Event::TYPE_OPML_OK) {
                 RDR_Import::updateAllFeeds();
             }
             v("message", $event->getText());
         }
     }
     if (post("new") && trim(post("val"))) {
         RDR_Category::get(post("val"));
         redirect(url()->getUri(), 302);
     }
     if (req()->isAjax()) {
         $categories = user()->getCategories();
         $feeds = user()->getFeeds();
         if (post("action") == "edit" && post("val")) {
             if (isset($categories[post("category")])) {
                 $category = $categories[post("category")];
                 if (post("feed")) {
                     $feed = arrayValue($feeds, post("feed"));
                     if ($feed) {
                         $feed->setCustomName($category, post("val"));
                         $category->store();
                     }
                 } else {
                     $category->name = post("val");
                     $category->store();
                 }
             }
         }
         if (post("action") == "move") {
             if (isset($categories[post("categoryOld")])) {
                 $categoryOld = $categories[post("categoryOld")];
                 $categoryNew = $categories[post("categoryNew")];
                 if (post("feed")) {
                     $feed = arrayValue($feeds, post("feed"));
//.........这里部分代码省略.........
开发者ID:nonconforme,项目名称:nreeda,代码行数:101,代码来源:Organize.class.php

示例11: upgrade

 public function upgrade()
 {
     needRole('user');
     $user = getRole('user');
     $product = apicall('product', 'newProduct', array($_REQUEST['product_type']));
     if ($product->upgrade($user, $_REQUEST['name'], $_REQUEST['product_id'])) {
         $this->_tpl->assign('msg', '升级成功');
     } else {
         $this->_tpl->assign('msg', '升级失败.' . $GLOBALS["last_error"]);
     }
     return $this->_tpl->fetch('public/msg.html');
 }
开发者ID:srdc2014,项目名称:vhms,代码行数:12,代码来源:product.ctl.php

示例12: onLoad


//.........这里部分代码省略.........
                         if (substr($file, 0, 1) == ".") {
                             continue;
                         }
                         if (!is_writable($file)) {
                             $count++;
                         }
                     }
                     if ($count) {
                         error(sprintf(t("update.3"), $count));
                     }
                     $version = RDR_Setting::get("latestversion")->value;
                     $data = array("message" => sprintf(t("update.5"), $version), "event" => "success", "next" => "prepare", "params" => array("version" => $version));
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "prepare":
                 try {
                     # downloading zip file from GIT
                     $url = "https://github.com/brainfoolong/nreeda/archive/" . get("version") . ".zip";
                     $data = RDR_FileContents::get($url);
                     if ($data === false) {
                         return;
                     }
                     $tmpZip = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update.zip";
                     file_put_contents($tmpZip, $data);
                     $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update";
                     if (!is_dir($updateDir)) {
                         mkdir($updateDir);
                     }
                     # removing all old files
                     $files = CHOQ_FileManager::getFiles($updateDir, true, true);
                     foreach ($files as $file) {
                         if (!is_dir($file)) {
                             unlink($file);
                         }
                     }
                     foreach ($files as $file) {
                         if (is_dir($file)) {
                             rmdir($file);
                         }
                     }
                     # extract zip file to tmp folder
                     $zip = new ZipArchive();
                     $zip->open($tmpZip);
                     $zip->extractTo($updateDir);
                     $zip->close();
                     $folder = $updateDir . "/nreeda-" . get("version");
                     $data = array("message" => t("update.9"), "event" => "success", "next" => "update", "params" => array("updatefolder" => $folder, "rootfolder" => CHOQ_ROOT_DIRECTORY, "updateurl" => url()->getByAlias("base", "modules/RDR/tmp/update/nreeda-" . get("version") . "/update.php")));
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "db":
                 try {
                     RDR_DBUpdate::run();
                     $data = array("message" => t("update.10"), "event" => "success", "next" => "cleanup");
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "cleanup":
                 try {
                     # deleting all update files
                     $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update";
                     if (is_dir($updateDir)) {
                         $files = CHOQ_FileManager::getFiles($updateDir, true, true);
                         foreach ($files as $file) {
                             if (!is_dir($file)) {
                                 unlink($file);
                             }
                         }
                         foreach ($files as $file) {
                             if (is_dir($file)) {
                                 rmdir($file);
                             }
                         }
                     }
                     if (is_dir($updateDir)) {
                         rmdir($updateDir);
                     }
                     $updateFile = CHOQ_ROOT_DIRECTORY . "/update.php";
                     if (file_exists($updateFile)) {
                         unlink($updateFile);
                     }
                     $data = array("message" => t("update.11"), "event" => "success");
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "disable":
                 RDR_Maintenance::disableMaintenanceMode();
                 break;
         }
         echo json_encode($data);
         return;
     }
     needRole(RDR_User::ROLE_ADMIN, true);
     view("RDR_BasicFrame", array("view" => $this));
 }
开发者ID:nonconforme,项目名称:nreeda,代码行数:101,代码来源:Update.class.php

示例13: onLoad

    /**
     * Load the View
     */
    public function onLoad()
    {
        if (!needRole()) {
            return;
        }
        # some ajax actions
        switch (post("action")) {
            case "admin-feed":
                if (needRole(RDR_User::ROLE_ADMIN)) {
                    $entry = RDR_Entry::getById(post("eid"));
                    $feed = RDR_Feed::getById(post("fid"));
                    ?>
                    <b><?php 
                    echo t("feedadmin.raw.1");
                    ?>
</b>
                    <div class="small">
                        <?php 
                    echo t("feedadmin.raw.2");
                    ?>
                    </div>
                    <code class="raw"><?php 
                    echo s('<div>' . $entry->text . '</div>');
                    ?>
</code><br/><br/>
                    <b><?php 
                    echo t("feedadmin.format.1");
                    ?>
</b>
                    <div class="small">
                        <?php 
                    echo t("feedadmin.format.2");
                    ?>
                    </div>
                    <code class="formated"></code><br/><br/>
                    <b><?php 
                    echo sprintf(t("feedadmin.js.1"), s(cut($feed->name, 30)));
                    ?>
</b>
                    <div class="small">
                        <?php 
                    echo nl2br(sprintf(t("feedadmin.js.2"), s('<p>'), 'html = $(html); html.find("p").remove()'));
                    ?>
<br/>
                        <textarea data-field="contentJS" style="width:90%" cols="45" rows="3"><?php 
                    echo s($feed->contentJS);
                    ?>
</textarea>
                    </div>
                    <?php 
                }
                return;
                break;
            case "readed":
                if (post("ids")) {
                    $entries = RDR_Entry::getByIds(post("ids"));
                    if ($entries) {
                        user()->loadReadedFlags(array_keys($entries));
                        $insertIds = $deleteIds = array();
                        foreach ($entries as $entry) {
                            $id = $entry->getId();
                            if ($id < user()->setting("init.entry")) {
                                continue;
                            }
                            if (isset(user()->_cacheReaded[$id])) {
                                $deleteIds[$id] = $id;
                            } else {
                                $insertIds[$id] = $id;
                            }
                        }
                        if ($insertIds) {
                            $query = "INSERT IGNORE INTO RDR_User_readed (o,k,v) VALUES ";
                            foreach ($insertIds as $id) {
                                $query .= " (" . user()->getId() . ", {$id}, 1), ";
                            }
                            $query = substr($query, 0, -2);
                            db()->query($query);
                        }
                        if ($deleteIds) {
                            $query = "DELETE FROM RDR_User_readed WHERE o = " . user()->getId() . " && k IN " . db()->toDb($deleteIds);
                        }
                        user()->updateReadedCount();
                    }
                }
                break;
            case "saved":
                if (post("ids")) {
                    $entry = RDR_Entry::getById(post("ids[0]"));
                    if ($entry) {
                        if (user()->getByKey("saved", $entry->getId())) {
                            user()->remove("saved", $entry->getId());
                        } else {
                            user()->add("saved", 1, $entry->getId());
                        }
                        user()->store();
                    }
                }
//.........这里部分代码省略.........
开发者ID:nonconforme,项目名称:nreeda,代码行数:101,代码来源:Ajax.class.php

示例14: onLoad

 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!needRole()) {
         return;
     }
     $jsonData = null;
     switch (post("action")) {
         case "delete-feed-user":
             $feed = RDR_Feed::getById(post("data[fid]"));
             if ($feed) {
                 $cats = user()->getCategories();
                 foreach ($cats as $category) {
                     $feeds = $category->feeds;
                     if ($feeds) {
                         foreach ($feeds as $key => $catFeed) {
                             if (compare($catFeed, $feed)) {
                                 unset($feeds[$key]);
                             }
                         }
                         if (count($feeds) != count($category->feeds)) {
                             $category->feeds = $feeds;
                             $category->store();
                         }
                     }
                 }
             }
             break;
         case "delete-feed-admin":
             if (needRole(RDR_User::ROLE_ADMIN)) {
                 $feed = RDR_Feed::getById(post("data[fid]"));
                 if ($feed) {
                     $feed->delete();
                 }
             }
             break;
         case "add-feed":
             $event = RDR_Import::addFeed(post("data[url]"), RDR_Category::get(post("data[category]")));
             if ($event->feed) {
                 RDR_Import::importFeedEntries($event->feed);
             }
             break;
         case "mark-all-as-readed":
             $cache = session("entry.ids.original");
             if ($cache) {
                 $ids = array_keys($cache);
                 user()->loadReadedFlags(array_keys($ids));
                 $insertIds = array();
                 foreach ($ids as $id) {
                     if (!isset(user()->_cacheReaded[$id])) {
                         $insertIds[$id] = $id;
                     }
                 }
                 if ($insertIds) {
                     $query = "INSERT IGNORE INTO RDR_User_readed (o,k,v) VALUES ";
                     foreach ($insertIds as $id) {
                         $query .= " (" . user()->getId() . ", {$id}, 1), ";
                     }
                     $query = substr($query, 0, -2);
                     db()->query($query);
                     user()->updateReadedCount();
                 }
             }
             break;
         case "update-setting-user":
             user()->setting(post("data[key]"), post("data[value]"));
             user()->store();
             break;
         case "update-newscache":
             user()->updateNewsCache();
             $jsonData = user()->getAjaxData();
             break;
         case "set-entries-readed":
             if (post("data[ids]")) {
                 $entries = RDR_Entry::getByIds(post("data[ids]"));
                 if ($entries) {
                     user()->loadReadedFlags(array_keys($entries));
                     $insertIds = $deleteIds = array();
                     foreach ($entries as $entry) {
                         $id = $entry->getId();
                         if ($id < user()->setting("init.entry")) {
                             continue;
                         }
                         if (isset(user()->_cacheReaded[$id])) {
                             $deleteIds[$id] = $id;
                         } else {
                             $insertIds[$id] = $id;
                         }
                     }
                     if ($insertIds) {
                         $query = "INSERT IGNORE INTO RDR_User_readed (o,k,v) VALUES ";
                         foreach ($insertIds as $id) {
                             $query .= " (" . user()->getId() . ", {$id}, 1), ";
                         }
                         $query = substr($query, 0, -2);
                         db()->query($query);
                     }
                     if ($deleteIds) {
//.........这里部分代码省略.........
开发者ID:nonconforme,项目名称:nreeda,代码行数:101,代码来源:API.class.php

示例15: getContent

    /**
     * Get content
     */
    public function getContent()
    {
        headline(t("dashboard"));
        $settings = array("note.opml.import" => array("url" => l("RDR_Organize")), "note.addfeed" => array("url" => ""), "note.bug" => array("url" => "https://bfldev.com/nreeda"), "note.opml.export" => array("url" => l("RDR_Organize")), "note.search" => array("url" => ""), "note.settings" => array("url" => ""));
        echo sprintf(t("hello"), '<b>' . user()->username . '</b>') . "<br/><br/>";
        foreach ($settings as $key => $data) {
            if (user()->setting($key)) {
                continue;
            }
            echo '<div class="note" data-id="' . $key . '" data-url="' . $data["url"] . '">' . t($key) . '</div>';
        }
        ?>

        <script type="text/javascript">
        $("#content .note").on("click", function(){
            var url = $(this).attr("data-url");
            var e = $(this);
            $.post(Global.vars.ajaxUrl, {action : "changesetting", "key" : $(this).attr("data-id"), "value" : 1}, function(data){
                e.remove();
                if(url){
                    if(url.match(/^http/)){
                        window.open(url);
                    }else{
                        window.location.href = url;
                    }
                }
            })
        });
        </script>

        <div class="spacer"></div>
        <?php 
        if (needRole(RDR_User::ROLE_ADMIN)) {
            headline(t("dashboard.eventlog"));
            $logs = RDR_Event::getByCondition(null, null, "-id", 50);
            ?>
            <div id="eventlog">
                <?php 
            if ($logs) {
                ?>
<input type="button" class="btn" value="<?php 
                echo t("dashboard.clearlog");
                ?>
"/><?php 
            }
            ?>
                <div class="spacer"></div>
                <?php 
            foreach ($logs as $log) {
                ?>
                    <div class="event">
                        <time datetime="<?php 
                echo $log->createTime->getUnixtime();
                ?>
" class="inline-btn"></time>
                        <?php 
                echo $log->getText();
                ?>
                    </div>
                <?php 
            }
            ?>
            </div>
            <div class="spacer"></div>
            <script type="text/javascript">
            $("#eventlog input.btn").on("click", function(){
                $.post(window.location.href, {clearlog : 1});
                $("#eventlog").remove();
            });
            </script>
            <?php 
            $file = CHOQ_ACTIVE_MODULE_DIRECTORY . "/logs/error.log.php";
            if (file_exists($file) && filesize($file)) {
                $data = file_get_contents($file);
                $data = substr($data, strpos($data, "\n\n"));
                headline(t("dashboard.errorlog"));
                ?>
                <div id="errorlog">
                    <input type="button" class="btn" value="<?php 
                echo t("dashboard.clearlog");
                ?>
"/>
                    <pre style="font-size:11px; overflow:auto; max-height:400px;"><code><?php 
                echo s(trim($data));
                ?>
</code></pre>
                </div>
                <script type="text/javascript">
                $("#errorlog input.btn").on("click", function(){
                    $.post(window.location.href, {clearerrorlog : 1});
                    $("#errorlog").remove();
                });
                </script>
                <?php 
            }
        }
    }
开发者ID:nonconforme,项目名称:nreeda,代码行数:100,代码来源:Home.class.php


注:本文中的needRole函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。