Beispiel #1
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     $object = Request::getVar('content', '', 'post', 'string', JREQUEST_ALLOWRAW);
     // Check if valid youtube or kaltura video
     // @FIXME: we need a safer way!
     if (preg_match('/<iframe(.*?)src="([^"]+)"([^>]*)>(.*?)<\\/iframe>/si', $object, $matches)) {
         if (stristr($matches[2], 'youtube')) {
             $this->asset['title'] = 'New YouTube video';
         } else {
             if (stristr($matches[2], 'vimeo')) {
                 $this->asset['title'] = 'New Vimeo video';
             } else {
                 if (stristr($matches[2], 'blip')) {
                     $this->asset['title'] = 'New Blip.tv video';
                 } else {
                     if (stristr($matches[2], 'kaltura')) {
                         $this->asset['title'] = 'New Kaltura video';
                     }
                 }
             }
         }
     } elseif (preg_match('/\\<script[\\s]+(type="text\\/javascript")?[\\s]*src="http[s]*\\:\\/\\/cdnapi(sec)?\\.kaltura\\.com/is', $object)) {
         $this->asset['title'] = 'New Kaltura video';
     } else {
         return array('error' => 'Content did not match the pre-defined filter for an object');
     }
     $this->asset['type'] = !empty($this->asset['type']) ? $this->asset['type'] : 'video';
     $this->asset['subtype'] = !empty($this->asset['subtype']) ? $this->asset['subtype'] : 'embedded';
     $this->asset['content'] = $object;
     // Return info
     return parent::create();
 }
Beispiel #2
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     $url = Request::getVar('content');
     // Allow for multiple entries at once
     if (strstr($url, ',')) {
         $urls = explode(',', $url);
         $urls = array_map('trim', $urls);
     } elseif (strstr($url, ' ')) {
         $urls = explode(' ', $url);
         $urls = array_map('trim', $urls);
     } elseif (strstr($url, "\n")) {
         $urls = explode("\n", $url);
         $urls = array_map('trim', $urls);
     } elseif (strstr($url, "\r\n")) {
         $urls = explode("\r\n", $url);
         $urls = array_map('trim', $urls);
     } else {
         $urls = (array) $url;
     }
     $return = array();
     foreach ($urls as $url) {
         if (!preg_match('/^(http[s]*\\:\\/\\/)?([0-9A-Za-z\\.\\/\\-\\=\\:\\?\\_\\&\\%\\~]+)$/', $url, $matches)) {
             return array('error' => 'Content did not match the pre-defined filter');
         }
         // Try to help users out by being a little smarter about url provided
         if (!preg_match('/^http[s]*\\:\\/\\//', $url) && strstr($url, '.')) {
             $url = 'http://' . $url;
         }
         $this->asset['title'] = $matches[2];
         $this->asset['type'] = 'url';
         $this->asset['subtype'] = 'link';
         $this->asset['url'] = $url;
         // Return info
         $r = parent::create();
         $return[] = $r['assets'];
     }
     return $return;
 }
Beispiel #3
0
 /**
  * Create method for this handler
  *
  * @return string - javascript to be run
  **/
 public function create()
 {
     // Include needed files
     require_once dirname(__DIR__) . DS . 'form.php';
     // Check to make sure a file was provided
     if (isset($_FILES['files'])) {
         $file = $_FILES['files']['name'][0];
         // Get the file extension
         $pathinfo = pathinfo($file);
         $filename = $pathinfo['filename'];
         $ext = $pathinfo['extension'];
     } else {
         return array('error' => 'No files provided');
     }
     // Instantiate form object
     $pdf = PdfForm::fromPostedFile('files');
     // No error, then render the images
     if (!$pdf->hasErrors()) {
         $pdf->renderPageImages();
     } else {
         return array('error' => $pdf->getErrors());
     }
     // Grab the newly created form id
     $id = $pdf->getId();
     $subtype = 'quiz';
     if (strstr($filename, 'exam') !== false) {
         $subtype = 'exam';
     } elseif (strstr($filename, 'homework') !== false) {
         $subtype = 'homework';
     }
     // Save the actual asset
     $this->asset['title'] = $filename;
     $this->asset['type'] = 'form';
     $this->asset['subtype'] = $subtype;
     $this->asset['url'] = $id;
     $this->asset['graded'] = 1;
     $this->asset['grade_weight'] = $subtype;
     // Call the primary create method on the file asset handler
     $return = parent::create();
     // Check for errors in response
     if (array_key_exists('error', $return)) {
         return array('error' => $return['error']);
     } else {
         // Set the asset id on the form
         $pdf->setAssetId($return['assets']['asset_id']);
         $gid = Request::getVar('course_id');
         $oid = Request::getVar('offering');
         // Build our JavaScript to return to the view to be executed
         $js = "// Open up forms in a lightbox\n\t\t\t\t\$.fancybox({\n\t\t\t\t\tfitToView: false,\n\t\t\t\t\tautoResize: false,\n\t\t\t\t\tautoSize: false,\n\t\t\t\t\theight: (\$(window).height())*2/3,\n\t\t\t\t\tcloseBtn: false,\n\t\t\t\t\tmodal: true,\n\t\t\t\t\ttype: 'iframe',\n\t\t\t\t\tiframe: {\n\t\t\t\t\t\tpreload : false\n\t\t\t\t\t},\n\t\t\t\t\thref: '/courses/" . $gid . "/" . $oid . "/form.layout?formId=" . $id . "&tmpl=component',\n\t\t\t\t\tafterLoad: function() {\n\t\t\t\t\t\tvar iframe = \$('.fancybox-iframe');\n\t\t\t\t\t\tiframe.load(function() {\n\t\t\t\t\t\t\tvar frameContents = \$('.fancybox-iframe').contents();\n\n\t\t\t\t\t\t\tvar navHeight = frameContents.find('.navbar').height();\n\t\t\t\t\t\t\tframeContents.find('.main.section.courses-form').css('margin-bottom', navHeight);\n\n\t\t\t\t\t\t\t// Highjack the 'done' button to close the iframe\n\t\t\t\t\t\t\tframeContents.find('#done').bind('click', function(e) {\n\t\t\t\t\t\t\t\te.preventDefault();\n\n\t\t\t\t\t\t\t\t\$.fancybox.close();\n\n\t\t\t\t\t\t\t\t// Remove progress bar\n\t\t\t\t\t\t\t\tHUB.CoursesOutline.asset.resetProgresBar(progressBarId, 0);\n\n\t\t\t\t\t\t\t\t// Get the form data and set the published value to 2 for deleted\n\t\t\t\t\t\t\t\tvar formData = form.serializeArray();\n\t\t\t\t\t\t\t\tformData.push({'name':'published', 'value':'2'});\n\t\t\t\t\t\t\t\tformData.push({'name':'id', 'value':'" . $this->assoc['asset_id'] . "'});\n\n\t\t\t\t\t\t\t\t// We've already saved the asset, so we need to mark asset as deleted\n\t\t\t\t\t\t\t\t\$.ajax({\n\t\t\t\t\t\t\t\t\turl: '/api/courses/asset/save',\n\t\t\t\t\t\t\t\t\tdata: formData\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\t// Listen for savesuccessful call from iframe\n\t\t\t\t\t\t\$('body').on('savesuccessful', function( e, title ) {\n\t\t\t\t\t\t\t\$.fancybox.close();\n\n\t\t\t\t\t\t\tvar data = " . json_encode(array('assets' => array($return['assets']))) . ";\n\n\t\t\t\t\t\t\tdata.assets[0].asset_title = title;\n\n\t\t\t\t\t\t\tHUB.CoursesOutline.asset.insert(data, assetslist, {'progressBarId':progressBarId});\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});";
     }
     return array('js' => $js);
 }
Beispiel #4
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     $this->asset['title'] = Request::getString('title', '');
     $this->asset['type'] = 'text';
     $this->asset['subtype'] = 'wiki';
     if (!Request::getString('title', false)) {
         return array('error' => 'Please provide a title!');
     }
     if (!Request::getInt('id', false)) {
         // Create asset
         $this->asset['course_id'] = Request::getInt('course_id');
         $return = parent::create();
     } else {
         $this->asset['course_id'] = Request::getInt('course_id');
         $this->assoc['asset_id'] = Request::getInt('id');
         $this->assoc['scope_id'] = Request::getInt('scope_id');
         // Save asset
         $return = parent::save();
     }
     // If files are included, save them as well
     // @FIXME: share this with file upload if possible
     if (isset($_FILES['files'])) {
         // @FIXME: should these come from the global settings, or should they be courses specific
         // Get config
         $config = Component::params('com_media');
         // Max upload size
         $sizeLimit = $config->get('upload_maxsize');
         $sizeLimit = $sizeLimit * 1024 * 1024;
         // Get courses config
         $cconfig = Component::params('com_courses');
         // Loop through files and save them (they will potentially be coming in together, in a single request)
         for ($i = 0; $i < count($_FILES['files']['name']); $i++) {
             $file = $_FILES['files']['name'][$i];
             $size = (int) $_FILES['files']['size'][$i];
             // Get the file extension
             $pathinfo = pathinfo($file);
             $filename = $pathinfo['filename'];
             $ext = $pathinfo['extension'];
             // Check to make sure we have a file and its not too big
             if ($size == 0) {
                 return array('error' => 'File is empty');
             }
             if ($size > $sizeLimit) {
                 $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
                 return array('error' => "File is too large. Max file upload size is {$max}");
             }
             // Build the upload path if it doesn't exist
             require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'asset.php';
             $asset = new \Components\Courses\Models\Asset($this->assoc['asset_id']);
             $uploadDirectory = PATH_APP . DS . $asset->path($this->asset['course_id']);
             // Make sure upload directory exists and is writable
             if (!is_dir($uploadDirectory)) {
                 if (!\Filesystem::makeDirectory($uploadDirectory)) {
                     return array('error' => 'Server error. Unable to create upload directory');
                 }
             }
             if (!is_writable($uploadDirectory)) {
                 return array('error' => 'Server error. Upload directory isn\'t writable');
             }
             // Get the final file path
             $target_path = $uploadDirectory . $filename . '.' . $ext;
             // Move the file to the site folder
             set_time_limit(60);
             // Scan for viruses
             if (!\Filesystem::isSafe($_FILES['files']['tmp_name'][$i])) {
                 // Scan failed, return an error
                 return array('error' => 'File rejected because the anti-virus scan failed.');
             }
             if (!($move = move_uploaded_file($_FILES['files']['tmp_name'][$i], $target_path))) {
                 return array('error' => 'Move file failed');
             }
         }
     }
     // Return info
     return $return;
 }