Пример #1
0
 public static function getNode($settingName)
 {
     $metaValue = (int) self::byName($settingName);
     $node = new NodeModel();
     $node->loadByPK($metaValue);
     return $node->hasLoaded() ? $node : false;
 }
Пример #2
0
 public function _before_edit()
 {
     $map['id'] = $_REQUEST['id'];
     $node = new NodeModel();
     $menu = $node->getMenu();
     $pid = $node->where($map)->getField('pid');
     $selecttree = outNodeSelect($menu, $pid);
     $this->assign('selecttree', $selecttree);
 }
Пример #3
0
 public function updateJson()
 {
     $id = Ajde::app()->getRequest()->getParam('id');
     $meta = Ajde::app()->getRequest()->getPostParam('meta');
     $key = Ajde::app()->getRequest()->getPostParam('key');
     $value = Ajde::app()->getRequest()->getPostParam('value');
     $model = new NodeModel();
     $model->loadByPK($id);
     $success = false;
     if ($meta) {
         $model->saveMetaValue($key, $value);
         $success = true;
     } else {
         $model->set($key, $value);
         $success = $model->save();
     }
     return ['success' => true, 'message' => $success ? 'Node updated' : 'Something went wrong'];
 }
Пример #4
0
 public function getItems()
 {
     $collection = new MenuCollection();
     $collection->filterByParent($this->id);
     $collection->orderBy('sort');
     $currentParentUrl = false;
     if ($current = Ajde_Cms::getInstance()->getRoutedNode()) {
         $currentParentUrl = $current->getParent() && $current->getParent()->hasLoaded() ? $current->getParent()->getUrl() : false;
     }
     $items = [];
     foreach ($collection as $item) {
         /* @var $item MenuModel */
         $name = $item->name;
         $target = '';
         $submenus = [];
         $current = '';
         $node = new NodeModel();
         if ($item->type == 'URL') {
             $url = $item->url;
             if (substr($url, 0, 7) === 'http://' || substr($url, 0, 8) === 'https://') {
                 $target = '_blank';
             }
         } else {
             if ($item->type == 'Node link') {
                 $node->loadByPK($item->node);
                 $url = $node->getUrl();
             } else {
                 if ($item->type == 'Submenu') {
                     $node->loadByPK($item->node);
                     $url = $node->getUrl();
                     $submenus = $item->getItems();
                     foreach ($submenus as $submenu) {
                         if ($submenu['current']) {
                             $current = 'active sub-active';
                         }
                     }
                 }
             }
         }
         if ($url == Ajde::app()->getRoute()->getOriginalRoute()) {
             $current = 'active';
         }
         if (Ajde::app()->getRoute()->getOriginalRoute() == '' && $url == config('routes.homepage')) {
             $current = 'active';
         }
         if ($url == $currentParentUrl) {
             $current = 'active sub-active';
         }
         if ($item->type == 'Node link' && !$node->hasLoaded()) {
         } else {
             $items[] = ['node' => $node, 'name' => $name, 'url' => $url, 'target' => $target, 'current' => $current, 'submenus' => $submenus];
         }
     }
     return $items;
 }
Пример #5
0
 public function detectNodeSlug(Ajde_Core_Route $route)
 {
     $slug = $route->getRoute();
     $slug = trim($slug, '/');
     $lastSlash = strrpos($slug, '/');
     if ($lastSlash !== false) {
         $slug = substr($slug, $lastSlash + 1);
     }
     $node = NodeModel::fromSlug($slug);
     if ($node) {
         $this->_detectedNode = $node;
         $route->setRoute($slug);
         $routes = config('routes.list');
         array_unshift($routes, ['%^(' . preg_quote($slug) . ')$%' => ['slug']]);
         Config::set('routes.list', $routes);
     }
 }
Пример #6
0
 public function view()
 {
     // we want to display published nodes only
     if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
         Ajde::app()->getRequest()->set('filterPublished', true);
     }
     // get the current slug
     $slug = $this->getSlug();
     $node = new NodeModel();
     $node->loadBySlug($slug);
     $this->node = $node;
     if ($node->checkPublished() === false) {
         Ajde_Dump::warn('Previewing unpublished node');
     }
     // check if we have a hit
     if (!$node->hasLoaded()) {
         Ajde::app()->getResponse()->redirectNotFound();
     }
     Ajde_Event::trigger($this, 'onAfterNodeLoaded', [$node]);
     // update cache
     Ajde_Cache::getInstance()->updateHash($node->hash());
     Ajde_Cache::getInstance()->updateHash($node->getChildren()->hash());
     Ajde_Cache::getInstance()->addLastModified(strtotime($node->updated));
     // set title
     if (!Ajde::app()->getDocument()->hasNotEmpty('title')) {
         Ajde::app()->getDocument()->setTitle($node->getTitle());
     }
     // set summary
     if ($node->summary) {
         Ajde::app()->getDocument()->setDescription($node->summary);
     }
     // set author
     $node->loadParent('user');
     /** @var UserModel $owner */
     $owner = $node->getUser();
     Ajde::app()->getDocument()->setAuthor($owner->getFullname());
     // set template
     $nodetype = $node->getNodetype();
     $action = str_replace(' ', '_', strtolower($nodetype->get($nodetype->getDisplayField())));
     $this->setAction($action);
     // featured image
     if ($image = $node->featuredImage()) {
         Ajde::app()->getDocument()->setFeaturedImage($image);
     }
     // pass node to document, only first
     $layout = Ajde::app()->getDocument()->getLayout();
     if (!$layout->hasAssigned('node')) {
         $layout->assign('node', $node);
     }
     // pass node to view
     $this->getView()->assign('node', $node);
     // render the temnplate
     return $this->render();
 }
Пример #7
0
    function nodeAction()
    {
        $node = NodeModel::init();
        //-------------------------------//
        //--------AJAX REQUEST-----------//
        //------------------------------//
        if (@$_GET['ajax_change_modul_position']) {
            if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['position'])) {
                dibi::query("UPDATE node SET position=%i", $_GET['position'], " WHERE id_node=%i", $_GET['id_node_ajax']);
                $node->invalidateCache();
            }
            exit;
        }
        if (@$_GET['ajax_change_modul_visible']) {
            if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['modul_visible'])) {
                dibi::query("UPDATE node SET visible=%s", $_GET['modul_visible'], " WHERE id_node=%i", $_GET['id_node_ajax']);
            }
            $node->invalidateCache();
            //      	echo dibi::$sql;
            exit;
        }
        //------SITE MAP pre premiestnenie modulu
        if (isset($_GET['ajax_show_site_map_for_modul'])) {
            $m = new MenuItem();
            $m->doTreeSelectMoveModul(0, 0, $_GET['id_menu_item'], $_GET['id_type_modul']);
            echo '<form action="" method="post">
        		<select name="id_menu_item_for_change">';
            echo $m->doTreeSelectMoveModulText;
            echo '<input type="hidden" name="id_type_modul" value="' . htmlspecialchars($_GET['id_type_modul']) . '" />
		       <input type="hidden" name="id_node" value="' . htmlspecialchars($_GET['id_node']) . '" />
		       <input type="submit" name="changeModulParent" value="Ulož" /> 
      		</form>';
            exit;
        }
        if (isset($_POST['changeModulParent'])) {
            $this->changeModulParent();
            $node->invalidateCache();
            header("Location: ?id_menu_item=" . $_POST['id_menu_item_for_change'] . "&showModulsOnPage=1");
            exit;
        }
        if (isset($_GET['id_menu_item']) and isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) {
            if (!dibi::fetchSingle("SELECT COUNT(*) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " AND id_type_modul=%i", $_GET['id_type_modul'], " AND id_node=%i", $_GET['id_modul'])) {
                header("Location:admin.php");
                exit;
            }
        }
        if (isset($_GET['addnode']) and isset($_GET['id_type_modul']) or isset($_POST['addModulToMenu'])) {
            if (isset($_POST['addModulToMenu'])) {
                $id_type_modul = $_POST['id_type_modul'];
            } else {
                $id_type_modul = $_GET['id_type_modul'];
            }
            $sequence = dibi::fetchSingle("SELECT MAX(sequence) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item']) + 1;
            $session = NEnvironment::getSession('Authentication');
            $config = NEnvironment::getConfig();
            $arr = array('id_user' => NEnvironment::getUser()->getIdentity()->id, 'id_menu_item' => $_GET['id_menu_item'], 'sequence' => $sequence, 'id_type_modul' => $id_type_modul, 'visible' => $config['NODE_VISIBLE']);
            dibi::query("INSERT INTO node ", $arr);
            $this->addModul(dibi::insertId(), $id_type_modul);
            $node->invalidateCache();
        }
        //zmenenie poradia
        if (isset($_GET['modul_id_up']) or isset($_GET['modul_id_down'])) {
            $this->changeOrderNode();
            $node->invalidateCache();
            header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&showModulsOnPage=1");
            exit;
        }
        //ak je iba jeden modul, hned sa zobrazi ale iba ak nieje setnuta section a showModulsOnPage
        if (isset($_GET['id_menu_item']) and !isset($_GET['id_type_modul']) and !isset($_GET['section']) and !isset($_GET['showModulsOnPage']) and !isset($_GET['changeMenuItem'])) {
            $l = dibi::fetch("SELECT *, COUNT(*) as node_count FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " ORDER BY sequence");
            if ($l['node_count'] == 1) {
                header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&id_type_modul=" . $l['id_type_modul'] . "&id_modul=" . $l['id_node']);
                exit;
            }
        }
        //pridanie do premenej activeModul instanciu objektu
        if (isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) {
            $this->activeModul = $this->nodeFactory($_GET['id_type_modul']);
            $this->activeModul->action();
        }
        if (isset($_GET['id_modul_del']) and is_numeric($_GET['id_modul_del'])) {
            $this->deleteNode(NULL, $_GET['id_modul_del']);
            $node->invalidateCache();
            header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item']);
            exit;
        }
    }
Пример #8
0
 /**
  * 获取菜单
  */
 public function get_menu($leve)
 {
     $nodemod = new NodeModel();
     if ($_SESSION[C('ADMIN_AUTH_KEY')]) {
         //超级管理员
         $list = $nodemod->get_node($leve);
         foreach ($list as $k => $v) {
             if ($leve == 1) {
                 $list[$k]['url'] = U($v['name'] . "/index");
             } else {
                 $list[$k]['url'] = U($this->getActionName() . "/" . strtolower($v['name']));
             }
             $list[$k]['name'] = strtolower($v['name']);
         }
     } else {
         //非超级管理员
         $list = $nodemod->get_user_node($leve, $_SESSION['my_info']['a_id']);
         foreach ($list as $k => $v) {
             if ($leve == 1) {
                 $list[$k]['url'] = U($v['name'] . "/index");
             } else {
                 $list[$k]['url'] = U($this->getActionName() . "/" . strtolower($v['name']));
             }
             $list[$k]['name'] = strtolower($v['name']);
         }
     }
     if ($list) {
         return $list;
     } else {
         return false;
     }
 }
Пример #9
0
 /**
 * 
 $criteria =  new CDbCriteria();
 $criteria->condition = "id = 1 or id =1";
 $node = Node::find('post',$criteria); 
 Node::find('post',1); 
 */
 static function find($table, $criteria, $pager = false, $pageSize = 10)
 {
     if (!is_object($criteria)) {
         $id = $criteria;
     }
     //所以字段key以及对应的model
     $cache = cache('node__field_table');
     $now = $cache[$table];
     $realTable = "field_" . $table;
     //设置NodeModel的表名
     NodeModel::$_table = $realTable;
     $t = new NodeModel();
     $t->refreshMetaData();
     if (is_object($criteria)) {
         if (true === $pager) {
             $count = NodeModel::model()->count($criteria);
             $pages = new CPagination($count);
             $pages->pageSize = $pageSize;
             $pages->applyLimit($criteria);
         }
         $posts = NodeModel::model()->findAll($criteria);
         if (!$posts) {
             return null;
         }
         foreach ($posts as $r) {
             $allRows[] = static::find($table, $r->id);
         }
         if (true === $pager) {
             $out = array('posts' => $allRows, 'pages' => $pages);
             return $out;
         }
         if ($criteria->limit == 1) {
             return ArrHelper::first($allRows);
         }
         return $allRows;
     }
     $fields = cache('node__content_field');
     if (!fields) {
         return null;
     }
     $rows = NodeModel::model()->findByPk($id);
     foreach ($fields[$table] as $k => $v) {
         $row[$k] = $rows->{$k};
     }
     //没有缓存是有问题的
     if (!$cache) {
         return $row;
     }
     foreach ($now as $k => $v) {
         $name = trim($v->name);
         $_relation_table = $realTable . "_" . $name;
         //真实的第三方表的内容
         $deep = $v->_relation_table;
         //是多个值的,并且是关联其他表的情况
         if ($v->relation && $v->mvalue == 1) {
             $allR = CDB()->from($_relation_table)->where('nid=:nid', array(':nid' => $id))->queryAll();
             if ($allR) {
                 foreach ($allR as $key => $al) {
                     $value = $al['value'];
                     $values = CDB()->from($deep)->where('id=:id', array(':id' => $value))->queryRow();
                     $all[$name][$value] = $values;
                 }
                 foreach ($all as $key => $value) {
                     $row[$key] = $value;
                 }
             }
         } else {
             if ($v->relation) {
                 $value = CDB()->from($deep)->where('id=:id', array(':id' => $row[$name]))->queryRow();
                 $row[$name] = $value;
             }
         }
     }
     return $row;
 }
Пример #10
0
 public function getNodeModelFromMetaValue($metaId)
 {
     $metaValue = (int) $this->getMetaValue($metaId);
     $node = new NodeModel();
     $node->loadByPK($metaValue);
     return $node->hasLoaded() ? $node : false;
 }