예제 #1
0
 /**
  * 生成应用的代码
  *
  */
 private function app_create_code($app_info)
 {
     import("@.ORG.file");
     $file = new file();
     //建立Action里的应用文件夹
     $rs = $file->create_folder("/Lib/Action/", $app_info['name']);
     if (!$rs) {
         return false;
     }
     //创建默认模块的文件
     $file->copy_file('/Lib/Action/', 'DemoAction.class.php', "/Lib/Action/{$app_info['name']}/", 'IndexAction.class.php');
     $content = $file->read_file("/Lib/Action/{$app_info['name']}/IndexAction.class.php");
     $content = str_replace('[应用名称]', $app_info['title'], $content);
     $content = str_replace('[描述]', $app_info['remark'], $content);
     $content = str_replace('[demo]', $_SESSION['nickname'], $content);
     $content = str_replace('[日期]', date('Y-m-d'), $content);
     $content = str_replace('[数据表名]', $app_info['table_name'], $content);
     $content = str_replace('class DemoAction extends', "class IndexAction extends", $content);
     $file->write_file("/Lib/Action/{$app_info['name']}/IndexAction.class.php", $content);
     //创建Tpl下相应模块的文件夹和默认操作HTML文件
     $rs = $file->create_folder("/Tpl/", $app_info['name']);
     if (!$rs) {
         return false;
     }
     $table_name = $this->_post('table_name') ? $this->_post('table_name') : '';
     $this->create_html($app_info['name'], 'Index', 'index', 'index', $table_name);
     $this->create_html($app_info['name'], 'Index', 'add', 'add', $table_name);
     $this->create_html($app_info['name'], 'Index', 'edit', 'edit', $table_name);
     $this->create_html($app_info['name'], 'Index', 'show', 'show', $table_name);
     $this->create_html($app_info['name'], 'Index', 'export', 'export', $table_name);
     return true;
 }
예제 #2
0
 /**
  * 创建操作
  *
  * @param unknown_type $action_info
  */
 private function create_action($action_info, $tpl, $app_name, $module_name, $table_name)
 {
     import("@.ORG.file");
     $file = new file();
     //创建Tpl下相应模块的文件夹和默认操作HTML文件
     $file->create_folder("/Tpl/", $app_name);
     $this->create_html($app_name, $module_name, $action_info['name'], $tpl, $table_name);
     return true;
 }
예제 #3
0
 /**
  * 添加应用,当添加一个应用时,在Lib目录下生成对应的文件夹,并且生成indexAction.class.php的基本类
  *
  */
 public function app_add()
 {
     if ($this->_post('act') == 'todo') {
         //先检测此应用是否存在。
         $rs = $this->node_check($this->_post('name'), $this->_post('pid'), $this->_post('level'));
         if (!$rs) {
             //在数据库中生成应用的节点信息
             $db_node = D('node');
             $app_info = $this->_post();
             if (false === $db_node->create()) {
                 $this->error($db_node->getError());
             }
             $app_id = $db_node->add();
             //建立Action里的应用文件夹
             import("@.ORG.file");
             $file = new file();
             $app_folder = $file->create_folder("/Lib/Action/", $app_info['name']);
             $param['title'] = $app_info['title'];
             $param['role_id'] = '[1][2]';
             $param['app'] = $app_info['name'];
             $menu_id = $this->add_menu($param);
             //系统管理员\企业管理层添加到一级菜单
             $app_info['id'] = $app_id;
             if (count($app_info['create_data'])) {
                 $table_name = $this->_post('table_name') ? $this->_post('table_name') : 'demo';
                 //在数据库中生成默认模块
                 $node_module_index['name'] = 'Index';
                 $node_module_index['title'] = $app_info['title'];
                 $node_module_index['status'] = 1;
                 $node_module_index['remark'] = $app_info['remark'];
                 $node_module_index['pid'] = $app_id;
                 $node_module_index['level'] = 2;
                 $node_module_index['id'] = $module_id = $db_node->data($node_module_index)->add();
                 if ($app_folder) {
                     $this->create_module_field($node_module_index, $table_name, $app_info['name']);
                 }
                 //在数据库中生成默认的5个操作,index,add,edit,show,export
                 $node_action['status'] = 1;
                 $node_action['pid'] = $module_id;
                 $node_action['level'] = 3;
                 //创建Tpl下相应模块的文件夹和默认操作HTML文件
                 $file->create_folder("/Tpl/", $app_info['name']);
                 foreach ($app_info['create_data'] as $val) {
                     switch ($val) {
                         case 'index':
                             //列表
                             $node_action['name'] = 'index';
                             $node_action['title'] = '数据列表';
                             $node_action['remark'] = '系统自动生成的默认操作列表';
                             $db_node->data($node_action)->add();
                             $this->create_html($app_info['name'], 'Index', 'index', 'index', $table_name);
                             //生成列表菜单
                             $url = U("{$app_info['name']}/{$node_module_index['name']}/{$node_action['name']}");
                             $param['title'] = '数据管理';
                             $param['role_id'] = '[1][2]';
                             $param['parent_id'] = $menu_id;
                             $param['position'] = 'menu';
                             $param['target'] = 'main-frame';
                             $param['url'] = $url;
                             $param['app'] = $app_info['name'];
                             $param['module'] = 'Index';
                             $menu_id = $this->add_menu($param);
                             break;
                         case 'add':
                             //添加
                             $node_action['name'] = 'add';
                             $node_action['title'] = '添加信息';
                             $node_action['remark'] = '系统自动生成的默认添加操作';
                             $db_node->data($node_action)->add();
                             $this->create_html($app_info['name'], 'Index', 'add', 'add', $table_name);
                             //生成添加信息菜单
                             $param['title'] = '添加信息';
                             $param['role_id'] = '[1][2]';
                             $param['parent_id'] = $menu_id;
                             $param['position'] = 'main';
                             $param['target'] = '_self';
                             $param['url'] = "javascript:dialog_add();";
                             $param['app'] = $app_info['name'];
                             $param['module'] = 'Index';
                             $this->add_menu($param);
                             break;
                         case 'edit':
                             //修改
                             $node_action['name'] = 'edit';
                             $node_action['title'] = '修改信息';
                             $node_action['remark'] = '系统自动生成的默认修改操作';
                             $db_node->data($node_action)->add();
                             $this->create_html($app_info['name'], 'Index', 'edit', 'edit', $table_name);
                             break;
                         case 'show':
                             //显示
                             $node_action['name'] = 'show';
                             $node_action['title'] = '显示信息';
                             $node_action['remark'] = '系统自动生成的默认添回操作';
                             $db_node->data($node_action)->add();
                             $this->create_html($app_info['name'], 'Index', 'show', 'show', $table_name);
                             break;
                         case 'export':
                             //导出
                             $node_action['name'] = 'export';
                             $node_action['title'] = '导出列表';
                             $node_action['remark'] = '系统自动生成的默认导出列表的所有信息';
                             $db_node->data($node_action)->add();
                             $this->create_html($app_info['name'], 'Index', 'export', 'export', $table_name);
                             break;
                     }
                     //end switch ($val) {
                 }
                 //end foreach ($app_info['create_data'] as $val){
                 //在配置文件中要自动加入这个应用
                 $content = $file->read_file('/Conf/sys_app_group_list.php');
                 $content = str_replace('";', ",{$app_info['name']}\";", $content);
                 $file->write_file('/Conf/sys_app_group_list.php', $content, true);
             }
             //end if (count($app_info['create_data'])){
             $this->success('操作成功!');
         } else {
             $this->error('此应用已存在');
         }
     } else {
         $this->display();
     }
 }
예제 #4
0
 public function import_sample($ws = null)
 {
     global $DB;
     global $website;
     global $theme;
     global $events;
     if (is_null($ws)) {
         $ws = $website;
     }
     if (!file_exists(NAVIGATE_PATH . '/themes/' . $this->name . '/' . $this->name . '_sample.zip')) {
         throw new Exception(t(56, 'Unexpected error'));
     }
     $ptf = NAVIGATE_PRIVATE . '/tmp/' . $this->name . '_sample';
     core_remove_folder($ptf);
     // decompress the zip file
     $extracted = false;
     $zip = new ZipArchive();
     if ($zip->open(NAVIGATE_PATH . '/themes/' . $this->name . '/' . $this->name . '_sample.zip') === TRUE) {
         @mkdir($ptf, 0777, true);
         $extracted = $zip->extractTo($ptf);
         if (!$extracted) {
             throw new Exception(t(56, 'Unexpected error'));
         }
         $zip->close();
     }
     // website languages (add website included languages)
     if (file_exists($ptf . '/languages.var_export')) {
         eval('$wlangs = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/languages.var_export')) . ';');
     } else {
         $wlangs = unserialize(file_get_contents($ptf . '/languages.serialized'));
     }
     if (!is_array($wlangs)) {
         $wlangs = array();
     }
     foreach ($wlangs as $lcode => $loptions) {
         if (!is_array($ws->languages) || !in_array($lcode, array_keys($ws->languages))) {
             $ws->languages[$lcode] = $loptions;
         }
     }
     // theme options
     if (file_exists($ptf . '/theme_options.var_export')) {
         eval('$toptions = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/theme_options.var_export')) . ';');
     } else {
         $toptions = unserialize(file_get_contents($ptf . '/theme_options.serialized'));
     }
     $ws->theme_options = $toptions;
     $ws->save();
     // folders (if available)
     $theme_files_parent = file::create_folder($this->name, "folder/generic", 0, $ws->id);
     $folders = array();
     if (file_exists($ptf . '/folders.var_export')) {
         // available since v2.1.2
         eval('$folders_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/folders.var_export')) . ';');
     }
     if (!empty($folders_or)) {
         // assume folders are defined in order (first the parents, then their children)
         foreach ($folders_or as $f) {
             // error protection
             if (empty($f->id)) {
                 continue;
             }
             $folders[$f->id] = new file();
             $folders[$f->id]->load_from_resultset(array($f));
             $folders[$f->id]->id = 0;
             $folders[$f->id]->website = $ws->id;
             if (isset($folders[$f->parent])) {
                 $folders[$f->id]->parent = $folders[$f->parent]->id;
             } else {
                 $folders[$f->id]->parent = $theme_files_parent;
             }
             $folders[$f->id]->insert();
         }
     }
     // files
     $files = array();
     if (file_exists($ptf . '/files.var_export')) {
         eval('$files_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/files.var_export')) . ';');
     } else {
         $files_or = unserialize(file_get_contents($ptf . '/files.serialized'));
     }
     foreach ($files_or as $f) {
         // error protection
         if (empty($f->id)) {
             continue;
         }
         $files[$f->id] = new file();
         $files[$f->id]->load_from_resultset(array($f));
         $files[$f->id]->id = 0;
         $files[$f->id]->website = $ws->id;
         if (isset($folders[$f->parent])) {
             $files[$f->id]->parent = $folders[$f->parent]->id;
         } else {
             $files[$f->id]->parent = $theme_files_parent;
         }
         $files[$f->id]->insert();
         // finally copy the sample file
         @copy($ptf . '/files/' . $f->id, NAVIGATE_PRIVATE . '/' . $ws->id . '/files/' . $files[$f->id]->id);
     }
     // structure
     $structure = array();
     if (file_exists($ptf . '/structure.var_export')) {
         eval('$structure_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/structure.var_export')) . ';');
     } else {
         $structure_or = unserialize(file_get_contents($ptf . '/structure.serialized'));
     }
     // hide existing structure entries
     $DB->execute('
         UPDATE nv_structure
            SET permission = 2, visible = 0
          WHERE website = ' . $ws->id);
     // we need to insert the old categories in order, in other words, the parents before its children
     // so to make things easy, we loop until we have no more categories to insert
     // this could lead to an infinite loop, so we have to add a simple protection
     $structure_categories_or = $structure_or;
     $changes = true;
     while (!empty($structure_categories_or) && $changes) {
         $changes = false;
         foreach ($structure_categories_or as $si => $category) {
             if (empty($category)) {
                 continue;
             }
             $old_category_id = $category->id;
             $category->id = 0;
             $category->website = $ws->id;
             if ($category->parent > 0 && !isset($structure[$category->parent])) {
                 // this structure entry needs a parent category that's not yet inserted
                 // ignore the current entry until the next loop
                 continue;
             }
             // if this category has a parent != root, update the parent id with the new value given
             if ($category->parent > 0) {
                 $category->parent = $structure[$category->parent]->id;
             }
             $category->insert();
             $changes = true;
             $structure[$old_category_id] = $category;
             unset($structure_categories_or[$si]);
         }
         $structure_categories_or = array_filter($structure_categories_or);
     }
     // elements
     $items = array();
     if (file_exists($ptf . '/items.var_export')) {
         eval('$items_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/items.var_export')) . ';');
     } else {
         $items_or = unserialize(file_get_contents($ptf . '/items.serialized'));
     }
     foreach ($items_or as $item) {
         // error protection
         if (empty($item->id)) {
             continue;
         }
         $old_item_id = $item->id;
         $item->id = 0;
         $item->website = $ws->id;
         // if this category has a parent != root, update the parent id with the new value given
         if ($item->category > 0) {
             $item->category = $structure[$item->category]->id;
         }
         $item->dictionary = theme::import_sample_parse_dictionary($item->dictionary, $files, $ws);
         // gallery images (correct FILE ids)
         if (!empty($item->galleries)) {
             $ngallery = array();
             foreach ($item->galleries as $gid => $gallery) {
                 foreach ($gallery as $fid => $caption) {
                     $ngallery[$files[$fid]->id] = $caption;
                 }
                 $item->galleries[$gid] = $ngallery;
             }
         }
         $item->insert();
         $items[$old_item_id] = $item;
     }
     // blocks
     $blocks = array();
     if (file_exists($ptf . '/blocks.var_export')) {
         eval('$blocks_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/blocks.var_export')) . ';');
     } else {
         $blocks_or = mb_unserialize(file_get_contents($ptf . '/blocks.serialized'));
     }
     if (!is_array($blocks_or)) {
         $blocks_or = array();
     }
     foreach ($blocks_or as $block) {
         // error protection
         if (empty($block->id)) {
             continue;
         }
         $old_block_id = $block->id;
         $block->id = 0;
         $block->website = $ws->id;
         // update structure entries (if used)
         if (!empty($block->categories)) {
             for ($bc = 0; $bc < count($block->categories); $bc++) {
                 $block->categories[$bc] = $structure[$block->categories[$bc]]->id;
             }
         }
         // update Actions (file/image)
         if (is_array($block->action['action-file'])) {
             foreach ($block->action['action-file'] as $lang => $file) {
                 $block->action['action-file'][$lang] = $files[$file]->id;
             }
         }
         if (is_array($block->action['action-image'])) {
             foreach (@$block->action['action-image'] as $lang => $file) {
                 $block->action['action-image'][$lang] = $files[$file]->id;
             }
         }
         // update Triggers (image/rolloverimage/flash/content/html)
         if (is_array($block->trigger['trigger-image'])) {
             foreach (@$block->trigger['trigger-image'] as $lang => $file) {
                 $block->trigger['trigger-image'][$lang] = $files[$file]->id;
             }
         }
         if (is_array($block->trigger['trigger-rollover'])) {
             foreach (@$block->trigger['trigger-rollover'] as $lang => $file) {
                 $block->trigger['trigger-rollover'][$lang] = $files[$file]->id;
             }
         }
         if (is_array($block->trigger['trigger-rollover-active'])) {
             foreach (@$block->trigger['trigger-rollover-active'] as $lang => $file) {
                 $block->trigger['trigger-rollover'][$lang] = $files[$file]->id;
             }
         }
         if (is_array($block->trigger['trigger-flash'])) {
             foreach (@$block->trigger['trigger-flash'] as $lang => $file) {
                 $block->trigger['trigger-flash'][$lang] = $files[$file]->id;
             }
         }
         $block->trigger['trigger-content'] = theme::import_sample_parse_array($block->trigger['trigger-content'], $files, $ws);
         $block->trigger['trigger-html'] = theme::import_sample_parse_array($block->trigger['trigger-html'], $files, $ws);
         $block->dictionary = theme::import_sample_parse_dictionary($block->dictionary, $files, $ws);
         // translate nv:// urls, which may be in:
         //      trigger->[trigger-links][lang][link][code] => link
         //      trigger->[trigger-content][lang] (as html code)
         //      trigger->[trigger-html][lang] (as html code)
         //      action->[action-web][lang]
         if (!empty($block->trigger['trigger-links'])) {
             foreach ($block->trigger['trigger-links'] as $lang => $block_trigger_link) {
                 foreach ($block_trigger_link['link'] as $btl_code => $btl_link) {
                     $btl_link = theme::import_sample_translate_nv_urls($btl_link, $structure, $items);
                     $block->trigger['trigger-links'][$lang]['link'][$btl_code] = $btl_link;
                 }
             }
         }
         if (!empty($block->trigger['trigger-content'])) {
             foreach ($block->trigger['trigger-content'] as $lang => $block_trigger_content) {
                 $block_trigger_content = theme::import_sample_translate_nv_urls($block_trigger_content, $structure, $items);
                 $block->trigger['trigger-content'][$lang] = $block_trigger_content;
             }
         }
         if (!empty($block->trigger['trigger-html'])) {
             foreach ($block->trigger['trigger-html'] as $lang => $block_trigger_content) {
                 $block_trigger_content = theme::import_sample_translate_nv_urls($block_trigger_content, $structure, $items);
                 $block->trigger['trigger-html'][$lang] = $block_trigger_content;
             }
         }
         if (!empty($block->action['action-web'])) {
             foreach ($block->action['action-web'] as $lang => $block_action_web) {
                 $block_action_web = theme::import_sample_translate_nv_urls($block_action_web, $structure, $items);
                 $block->action['action-web'][$lang] = $block_action_web;
             }
         }
         $block->insert();
         $blocks[$old_block_id] = $block;
     }
     // block_groups
     $block_groups = array();
     if (file_exists($ptf . '/block_groups.var_export')) {
         eval('$block_groups_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/block_groups.var_export')) . ';');
     } else {
         $block_groups_or = unserialize(file_get_contents($ptf . '/block_groups.serialized'));
     }
     foreach ($block_groups_or as $block_group) {
         // error protection
         if (empty($block_group->id)) {
             continue;
         }
         $old_block_group_id = $block_group->id;
         $block_group->id = 0;
         $block_group->website = $ws->id;
         // fix block IDs in group
         $new_selection = array();
         for ($bi = 0; $bi < count($block_group->blocks); $bi++) {
             if ($block_group->blocks[$bi]['type'] == 'block') {
                 $block_group->blocks[$bi]['id'] = $blocks[$block_group->blocks[$bi]['id']]->id;
             }
             $new_selection[] = $block_group->blocks[$bi];
         }
         $block_group->blocks = $new_selection;
         $block_group->insert();
         $block_groups[$old_block_group_id] = $block_group;
     }
     // comments
     if (file_exists($ptf . '/comments.var_export')) {
         eval('$comments_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/comments.var_export')) . ';');
     } else {
         $comments_or = unserialize(file_get_contents($ptf . '/comments.serialized'));
     }
     foreach ($comments_or as $comment) {
         if (empty($comment->item)) {
             continue;
         }
         $comment->id = 0;
         $comment->website = $ws->id;
         $comment->item = $items[$comment->item]->id;
         $comment->ip = '';
         $comment->insert();
     }
     // now that categories and elements have been inserted
     // we need to fix:
     //      structure jumps: [jump-branch, jump-item] to its new ID values
     //      items' sections: embedded nv:// urls
     // note: properties will be "translated" later
     // update structure properties
     foreach ($structure as $old_id => $entry) {
         foreach ($entry->dictionary as $elang => $properties) {
             if (!empty($properties['action-jump-item'])) {
                 $entry->dictionary[$elang]['action-jump-item'] = $items[$properties['action-jump-item']]->id;
             } else {
                 if (!empty($properties['action-jump-branch'])) {
                     $entry->dictionary[$elang]['action-jump-branch'] = $structure[$properties['action-jump-branch']]->id;
                 }
             }
             $entry->save();
         }
     }
     // find & update items' sections nv:// urls
     foreach ($items as $old => $element) {
         foreach ($element->dictionary as $eld_lang => $eld_field) {
             foreach ($eld_field as $eld_field_key => $eld_field_val) {
                 $html = theme::import_sample_translate_nv_urls($eld_field_val, $structure, $items);
                 $items[$old]->dictionary[$eld_lang][$eld_field_key] = $html;
             }
         }
         $items[$old]->save();
     }
     // translate website options; check for forced multilanguage options!
     $theme_options = array();
     for ($toi = 0; $toi < count($theme->options); $toi++) {
         $to = $theme->options[$toi];
         $to->value = $ws->theme_options->{$to->id};
         switch ($to->type) {
             case 'file':
             case 'image':
                 // is multi-language forced for this option?
                 if (in_array($to->multilanguage, array('true', '1'))) {
                     foreach ($to->value as $olang => $oval) {
                         if (isset($files[$oval]->id)) {
                             $to->value[$olang] = $files[$oval]->id;
                         }
                     }
                 } else {
                     if (isset($files[$to->value]->id)) {
                         $to->value = $files[$to->value]->id;
                     }
                 }
                 break;
             case 'category':
                 // is multi-language forced for this option?
                 if (in_array($to->multilanguage, array('true', '1'))) {
                     foreach ($to->value as $olang => $oval) {
                         if (isset($structure[$oval]->id)) {
                             $to->value[$olang] = $structure[$oval]->id;
                         }
                     }
                 } else {
                     if (isset($structure[$to->value]->id)) {
                         $to->value = $structure[$to->value]->id;
                     }
                 }
                 break;
             case 'element':
                 // is multi-language forced for this option?
                 if (in_array($to->multilanguage, array('true', '1'))) {
                     foreach ($to->value as $olang => $oval) {
                         if (isset($items[$oval]->id)) {
                             $to->value[$olang] = $items[$oval]->id;
                         }
                     }
                 } else {
                     if (isset($items[$to->value]->id)) {
                         $to->value = $items[$to->value]->id;
                     }
                 }
                 break;
             case 'categories':
                 // is multi-language forced for this option?
                 if (in_array($to->multilanguage, array('true', '1'))) {
                     foreach ($to->value as $olang => $oval) {
                         $property_categories_old = explode(',', $oval);
                         $property_categories_new = array();
                         foreach ($property_categories_old as $oc) {
                             $property_categories_new[] = $structure[$oc]->id;
                         }
                         $to->value[$olang] = implode(',', $property_categories_new);
                     }
                 } else {
                     $property_categories_old = explode(',', $to->value);
                     $property_categories_new = array();
                     foreach ($property_categories_old as $oc) {
                         $property_categories_new[] = $structure[$oc]->id;
                     }
                     $to->value = implode(',', $property_categories_new);
                 }
                 break;
             default:
                 // we don't need to change this type of value
         }
         // convert theme option definition to website option value
         $theme_options[$to->id] = $to->value;
     }
     $ws->theme_options = $theme_options;
     $ws->save();
     // properties
     // array ('structure' => ..., 'item' => ..., 'block' => ...)
     if (file_exists($ptf . '/properties.var_export')) {
         eval('$properties = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/properties.var_export')) . ';');
     } else {
         $properties = unserialize(file_get_contents($ptf . '/properties.serialized'));
     }
     $elements_with_properties = array('structure', 'item', 'block', 'block_group_block');
     foreach ($elements_with_properties as $el) {
         if ($el == 'structure') {
             $real = $structure;
         } else {
             if ($el == 'item') {
                 $real = $items;
             } else {
                 if ($el == 'block') {
                     $real = $blocks;
                 } else {
                     if ($el == 'block_group_block') {
                         $real = $block_groups;
                     } else {
                         continue;
                     }
                 }
             }
         }
         // unrecognized element type, ignore
         if (!is_array($properties[$el])) {
             continue;
         }
         foreach ($properties[$el] as $el_id => $el_properties) {
             if (empty($el_properties)) {
                 continue;
             }
             $item_uid = "";
             if ($el == 'block_group_block') {
                 // find each assigned block UID reference in this block group block
                 foreach ($el_properties as $item_uid => $el_properties_bg) {
                     theme::import_sample_properties($ws, $el_properties_bg, $el, $files, $structure, $items, $real, $el_id, $item_uid);
                 }
             } else {
                 theme::import_sample_properties($ws, $el_properties, $el, $files, $structure, $items, $real, $el_id, $item_uid);
             }
         }
     }
     // apply final settings from export
     if (file_exists($ptf . '/settings.var_export')) {
         eval('$settings_or = ' . str_replace("stdClass::__set_state", "(object)", file_get_contents($ptf . '/settings.var_export')) . ';');
     } else {
         // get first structure ID
         $structure_id = array_keys($structure);
         $structure_id = $structure_id[0];
         $settings_or = array('homepage' => $structure_id);
     }
     if (!empty($settings_or['favicon'])) {
         $ws->favicon = $files[$settings_or['favicon']]->id;
     }
     // what is the homepage?
     if (is_numeric($settings_or['homepage'])) {
         // homepage as a category ID
         $ws->homepage = $structure[$settings_or['homepage']]->id;
     } else {
         // homepage as a path
         $ws->homepage = $settings_or['homepage'];
     }
     $ws->save();
     core_remove_folder($ptf);
 }
예제 #5
0
 /**
  * 创建应用的各个文件
  */
 private function create_app($app_info)
 {
     import("@.ORG.file");
     $file = new file();
     //建立Action里的应用文件夹
     $file->create_folder("/Lib/Action/", $app_info['name']);
     //创建Tpl下相应模块的文件夹和默认操作HTML文件
     $file->create_folder("/Tpl/", $app_info['name']);
     //在配置文件中要自动加入这个应用
     $content = $file->read_file('/Conf/sys_app_group_list.php');
     $content = str_replace('";', ",{$app_info['name']}\";", $content);
     $file->write_file('/Conf/sys_app_group_list.php', $content, true);
     return true;
 }
예제 #6
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new file();
    switch ($_REQUEST['act']) {
        case 1:
            // json retrieval & operations
        // json retrieval & operations
        case "json":
            if ($_REQUEST['op'] == 'upload') {
                $tmp_name = $_REQUEST['tmp_name'];
                if ($tmp_name == "{{BASE64}}") {
                    $tmp_name = base64_encode($_REQUEST['name']);
                }
                $file = file::register_upload($tmp_name, $_REQUEST['name'], $_REQUEST['parent']);
                if (!empty($file)) {
                    echo json_encode(array('id' => $file->id, 'name' => $file->name));
                } else {
                    echo json_encode(false);
                }
            }
            switch ($_REQUEST['op']) {
                case 'create_folder':
                    file::create_folder($_REQUEST['name'], $_REQUEST['mime'], $_REQUEST['parent']);
                    echo json_encode(true);
                    break;
                case 'edit_folder':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $f->mime = $_REQUEST['mime'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'edit_file':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'duplicate_file':
                    //error_reporting(~0);
                    //ini_set('display_errors', 1);
                    $status = false;
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->id = 0;
                    $f->insert();
                    if (!empty($f->id)) {
                        $done = copy(NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . intval($_REQUEST['id']), NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $f->id);
                        $status = "true";
                        if (!$done) {
                            $f->delete();
                            $status = t(56, "Unexpected error");
                        }
                    }
                    echo $status;
                    break;
                case 'move':
                    if (is_array($_REQUEST['item'])) {
                        $ok = true;
                        for ($i = 0; $i < count($_REQUEST['item']); $i++) {
                            unset($item);
                            $item = new file();
                            $item->load($_REQUEST['item'][$i]);
                            $item->parent = $_REQUEST['folder'];
                            $ok = $ok & $item->update();
                        }
                        echo json_encode($ok ? true : false);
                    } else {
                        $item->load($_REQUEST['item']);
                        $item->parent = $_REQUEST['folder'];
                        echo json_encode($item->update());
                    }
                    break;
                case 'delete':
                    try {
                        $item->load($_REQUEST['id']);
                        $status = $item->delete();
                        echo json_encode($status);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    break;
                case 'permissions':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->access = intval($_POST['access']);
                        $item->permission = intval($_POST['permission']);
                        $item->enabled = intval($_POST['enabled']);
                        $item->groups = $_POST['groups'];
                        if ($item->access < 3) {
                            $item->groups = array();
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        echo json_encode(array('access' => $item->access, 'groups' => $item->groups, 'permission' => $item->permission, 'enabled' => $item->enabled));
                    }
                    break;
                case 'description':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->title = array();
                        $item->description = array();
                        foreach ($website->languages as $language) {
                            $lcode = $language['code'];
                            if (!isset($_REQUEST['titles'][$lcode])) {
                                break;
                            }
                            $item->title[$lcode] = $_REQUEST['titles'][$lcode];
                            $item->description[$lcode] = $_REQUEST['descriptions'][$lcode];
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        // return file title and description (alt)
                        $data = array('title' => $item->title, 'description' => $item->description);
                        echo json_encode($data);
                    }
                    break;
                case 'focalpoint':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->focalpoint = $_REQUEST['top'] . '#' . $_REQUEST['left'];
                        $status = $item->save();
                        // remove cached thumbnails
                        file::thumbnails_remove($item->id);
                        echo json_encode($status);
                    } else {
                        if (empty($item->focalpoint)) {
                            $item->focalpoint = '50#50';
                            $item->save();
                            // remove cached thumbnails
                            file::thumbnails_remove($item->id);
                        }
                        echo $item->focalpoint;
                    }
                    break;
                case 'video_info':
                    if ($_REQUEST['provider'] == 'youtube') {
                        $item->load_from_youtube($_REQUEST['reference'], false);
                        // force cache reload
                    } else {
                        if ($_REQUEST['provider'] == 'vimeo') {
                            $item->load_from_vimeo($_REQUEST['reference'], false);
                            // force cache reload
                        } else {
                            if (!empty($_REQUEST['reference']) && is_numeric($_REQUEST['reference'])) {
                                $item->load($_REQUEST['reference']);
                            } else {
                                if (is_numeric($_REQUEST['provider'])) {
                                    $item->load($_REQUEST['provider']);
                                } else {
                                    unset($item);
                                }
                            }
                            if (!empty($item)) {
                                // add some extra data
                                $item->extra = array('reference' => $item->id, 'link' => '', 'thumbnail' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_big' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_url' => 'img/icons/ricebowl/mimetypes/video.png', 'duration' => '', 'embed_code' => '<video src="' . file::file_url($item->id, 'inline') . '></video>');
                            }
                        }
                    }
                    if (!empty($item)) {
                        echo json_encode($item);
                    } else {
                        echo false;
                    }
                    break;
            }
            session_write_close();
            $DB->disconnect();
            exit;
            break;
        case 2:
            // show/edit item properties
        // show/edit item properties
        case "edit":
            $item->load($_REQUEST['id']);
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    unset($item);
                    $item = new file();
                    $item->load($_REQUEST['id']);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = files_item_properties($item);
            break;
        case 10:
        case 'media_browser':
            files_media_browser($_GET['limit'], $_GET['offset']);
            break;
        case 92:
            // pixlr (image editor) overlay remover
        // pixlr (image editor) overlay remover
        case 'pixlr_exit':
            ob_clean();
            file::thumbnails_remove(intval($_GET['id']));
            echo '
			<html>
			<head></head>
			<body>
			<script language="javascript" type="text/javascript">
				//window.parent.eval("$(\'#thumbnail-cache\').attr(\'src\', $(\'#thumbnail-cache\').attr(\'src\') + \'&refresh=\' + new Date().getTime());");
				window.parent.eval(\'$("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime());\');
				window.parent.eval("pixlr.overlay.hide();");
			</script>
			</body>
			</html>	
			';
            core_terminate();
            break;
            /*	
            case 91: // picnik editing
            	ob_clean();
            	
            	// $strPicnikUrl is the URL that we use to launch Picnik.
            	$strPicnikUrl = "http://www.picnik.com/service";	
            	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
            	$aPicnikParams['_apikey'] = $website->picnik_api_key;
            	// tell Picnik where to send the exported image
            	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
            	// give the export button a title
            	$aPicnikParams['_export_title'] = t(34, 'Save');
            	// turn on the close button, and tell it to come back here
            	//$aPicnikParams['_close_target'] = $strRoot;
            	// send in the previous "king" image in case the user feels like decorating it
            	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
            	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
            	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
            
            	// tell Picnik our name.  It'll use it in a few places as appropriate
            	$aPicnikParams['_host_name'] = 'Navigate';
            	// turn off the "Save &amp; Share" tab so users don't get confused
            	$aPicnikParams['_exclude'] = "out";
            
            	echo '<html><head></head><body>';
            
            	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
            	
            	// put all the API parameters into the form as hidden inputs
            	foreach( $aPicnikParams as $key => $value ) {
            		echo "<input type='hidden' name='$key' value='$value'/>\n";
            	}
            	
            	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
            	echo "<input type='submit' value='Picnik'/>\n";
            	echo "</form>";
            	echo '<script language="javascript" type="text/javascript">
            			document.forms[0].submit();
            		  </script>';
            	echo '</body></html>';
            
            	core_terminate();
            	break;
            */
        /*	
        case 91: // picnik editing
        	ob_clean();
        	
        	// $strPicnikUrl is the URL that we use to launch Picnik.
        	$strPicnikUrl = "http://www.picnik.com/service";	
        	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
        	$aPicnikParams['_apikey'] = $website->picnik_api_key;
        	// tell Picnik where to send the exported image
        	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
        	// give the export button a title
        	$aPicnikParams['_export_title'] = t(34, 'Save');
        	// turn on the close button, and tell it to come back here
        	//$aPicnikParams['_close_target'] = $strRoot;
        	// send in the previous "king" image in case the user feels like decorating it
        	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
        	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
        	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
        
        	// tell Picnik our name.  It'll use it in a few places as appropriate
        	$aPicnikParams['_host_name'] = 'Navigate';
        	// turn off the "Save &amp; Share" tab so users don't get confused
        	$aPicnikParams['_exclude'] = "out";
        
        	echo '<html><head></head><body>';
        
        	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
        	
        	// put all the API parameters into the form as hidden inputs
        	foreach( $aPicnikParams as $key => $value ) {
        		echo "<input type='hidden' name='$key' value='$value'/>\n";
        	}
        	
        	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
        	echo "<input type='submit' value='Picnik'/>\n";
        	echo "</form>";
        	echo '<script language="javascript" type="text/javascript">
        			document.forms[0].submit();
        		  </script>';
        	echo '</body></html>';
        
        	core_terminate();
        	break;
        */
        case 0:
            // list / search result
        // list / search result
        default:
            // show requested folder or search
            $out = files_browser($_REQUEST['parent'], $_REQUEST['navigate-quicksearch']);
            users_log::action($_REQUEST['fid'], intval($_REQUEST['parent']), 'list', '', json_encode($_REQUEST));
            break;
    }
    return $out;
}