Esempio n. 1
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function ajaxCreateTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_LOGIN_REQUIRED')));
         return;
     }
     // Ensure we have an ID to work with
     $listdir = strtolower(Request::getVar('dir', ''));
     if (!$listdir) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_NO_ID')));
         return;
     }
     if (substr($listdir, 0, 3) == 'tmp') {
         $item = new Item($listdir);
         if (!$item->exists()) {
             $item->set('id', 0);
             $item->set('state', 0);
             $item->set('title', $listdir);
             if (!$item->store()) {
                 echo json_encode(array('success' => false, 'errors' => $item->getErrors(), 'file' => 'http://', 'directory' => '', 'id' => $listdir));
                 return;
             }
         }
         $listdir = $item->get('id');
     }
     // Create database entry
     $asset = new Asset();
     $asset->set('item_id', intval($listdir));
     $asset->set('filename', 'http://');
     $asset->set('description', Request::getVar('description', '', 'post'));
     $asset->set('state', 1);
     $asset->set('type', 'link');
     if (!$asset->store()) {
         echo json_encode(array('success' => false, 'errors' => $asset->getErrors(), 'file' => 'http://', 'directory' => '', 'id' => $listdir));
         return;
     }
     //echo result
     echo json_encode(array('success' => true, 'file' => 'http://', 'directory' => '', 'id' => $listdir));
 }