Exemplo n.º 1
0
 public function upload()
 {
     /** import upload library **/
     _wpl_import('assets.packages.ajax_uploader.UploadHandler');
     $kind = wpl_request::getVar('kind', 0);
     $params = array();
     $params['accept_ext'] = wpl_flex::get_field_options(301);
     $extentions = explode(',', $params['accept_ext']['ext_file']);
     $ext_str = '';
     foreach ($extentions as $extention) {
         $ext_str .= $extention . '|';
     }
     // remove last |
     $ext_str = substr($ext_str, 0, -1);
     $ext_str = rtrim($ext_str, ';');
     $custom_op = array('upload_dir' => wpl_global::get_upload_base_path(), 'upload_url' => wpl_global::get_upload_base_url(), 'accept_file_types' => '/\\.(' . $ext_str . ')$/i', 'max_file_size' => $params['accept_ext']['file_size'] * 1000, 'min_file_size' => 1, 'max_number_of_files' => null);
     $upload_handler = new UploadHandler($custom_op);
     $response = json_decode($upload_handler->json_response);
     if (isset($response->files[0]->error)) {
         return;
     }
     $attachment_categories = wpl_items::get_item_categories('attachment', $kind);
     // get item category with first index
     $item_cat = reset($attachment_categories)->category_name;
     $index = floatval(wpl_items::get_maximum_index(wpl_request::getVar('pid'), wpl_request::getVar('type'), $kind, $item_cat)) + 1.0;
     $item = array('parent_id' => wpl_request::getVar('pid'), 'parent_kind' => $kind, 'item_type' => wpl_request::getVar('type'), 'item_cat' => $item_cat, 'item_name' => $response->files[0]->name, 'creation_date' => date("Y-m-d H:i:s"), 'index' => $index);
     wpl_items::save($item);
 }
Exemplo n.º 2
0
 private function save_dbst()
 {
     $dbst_id = wpl_request::getVar('dbst_id', 0);
     $post = wpl_request::get('post');
     $mode = 'edit';
     /** insert new field **/
     if (!$dbst_id) {
         $mode = 'add';
         $dbst_id = wpl_flex::create_default_dbst();
     }
     $q = '';
     foreach ($post as $field => $value) {
         if (substr($field, 0, 4) != 'fld_') {
             continue;
         }
         $key = substr($field, 4);
         if (trim($key) == '') {
             continue;
         }
         $q .= "`{$key}`='{$value}', ";
     }
     /** add options to query **/
     $options = wpl_flex::get_encoded_options($post, 'opt_', wpl_flex::get_field_options($dbst_id));
     $q .= "`options`='" . wpl_db::escape($options) . "', ";
     $q = trim($q, ", ");
     $query = "UPDATE `#__wpl_dbst` SET " . $q . " WHERE `id`='{$dbst_id}'";
     wpl_db::q($query, 'update');
     $dbst_type = wpl_flex::get_dbst_key('type', $dbst_id);
     $dbst_kind = wpl_flex::get_dbst_key('kind', $dbst_id);
     /** run queries **/
     if ($mode == 'add') {
         wpl_flex::run_dbst_type_queries($dbst_id, $dbst_type, $dbst_kind, 'add');
     }
     /** Multilingual **/
     if (wpl_global::check_addon('pro')) {
         wpl_addon_pro::multilingual($dbst_id);
     }
     /** trigger event **/
     wpl_global::event_handler('dbst_modified', array('id' => $dbst_id, 'mode' => $mode, 'kind' => $dbst_kind, 'type' => $dbst_type));
     /** echo response **/
     echo json_encode(array('success' => 1, 'message' => __('Field saved.', WPL_TEXTDOMAIN), 'data' => NULL));
     exit;
 }