示例#1
0
echo Lang::txt('COM_BILLBOARDS_FIELD_NAME');
?>
:</label><br />
					<input type="text" name="billboard[name]" id="billboardname" value="<?php 
echo $this->escape(stripslashes($this->row->name));
?>
" />
				</div>
				<div class="input-wrap">
					<label for="billboardcollection"><?php 
echo Lang::txt('COM_BILLBOARDS_FIELD_COLLECTION');
?>
:</label><br />
					<select name="billboard[collection_id]" id="billboardcollection">
						<?php 
$collections = Collection::all()->rows();
?>
						<?php 
if ($collections->count() > 0) {
    ?>
							<?php 
    foreach ($collections as $collection) {
        ?>
								<option value="<?php 
        echo $collection->id;
        ?>
"<?php 
        echo $collection->id == $this->row->collection_id ? ' selected="selected"' : '';
        ?>
>
									<?php 
 /**
  * Lists all billboards for a given collection
  *
  * @apiMethod GET
  * @apiUri    /billboards/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Collection identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     0
  * }
  * @return  void
  */
 public function readTask()
 {
     // Get the collection id
     $collection = Request::getInt('id', 0);
     // Load up the collection
     $collection = Collection::oneOrNew($collection);
     // Make sure we found a collection
     if ($collection->isNew()) {
         throw new Exception(Lang::txt('Collection not found'), 404);
     }
     $billboards = $collection->billboards()->select('name')->select('learn_more_target')->select('background_img')->whereEquals('published', 1)->rows();
     foreach ($billboards as $billboard) {
         $image = $billboard->get('background_img');
         $billboard->set('retina_background_img', $image);
         if (is_file(PATH_APP . DS . $image)) {
             $image_info = pathinfo($image);
             $retina_image = $image_info['dirname'] . DS . $image_info['filename'] . "@2x." . $image_info['extension'];
             if (file_exists(PATH_APP . DS . $retina_image)) {
                 $billboard->set('retina_background_img', $retina_image);
             }
         }
     }
     // Get the collection and its billboards
     $collection = array('id' => $collection->id, 'name' => $collection->name, 'billboards' => $billboards->toArray());
     $this->send(array('collection' => $collection));
 }
示例#3
0
 /**
  * Delete a billboard collection
  *
  * @return void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // Loop through the selected collections to delete
     // @TODO: maybe we should warn people if trying to delete a collection with associated billboards?
     foreach ($ids as $id) {
         $collection = Collection::oneOrFail($id);
         // Delete record
         $collection->destroy();
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BILLBOARDS_COLLECTION_SUCCESSFULLY_DELETED', count($ids)));
 }
示例#4
0
 /**
  * Save a billboard
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming, make sure to allow HTML to pass through
     $data = Request::getVar('billboard', array(), 'post', 'array', JREQUEST_ALLOWHTML);
     // Create object
     $billboard = Billboard::oneOrNew($data['id'])->set($data);
     // Check to make sure collection exists
     $collection = Collection::oneOrNew($billboard->collection_id);
     if ($collection->isNew()) {
         $collection->set('name', 'Default Collection')->save();
         $billboard->set('collection_id', $collection->id);
     }
     if (!$billboard->save()) {
         // Something went wrong...return errors
         foreach ($billboard->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('edit');
         $this->view->task = 'edit';
         $this->editTask($billboard);
         return;
     }
     // See if we have an image coming in as well
     $billboard_image = Request::getVar('billboard-image', false, 'files', 'array');
     // If so, proceed with saving the image
     if (isset($billboard_image['name']) && $billboard_image['name']) {
         // Build the upload path if it doesn't exist
         $image_location = $this->config->get('image_location', 'app' . DS . 'site' . DS . 'media' . DS . 'images' . DS . 'billboards');
         $uploadDirectory = PATH_ROOT . DS . trim($image_location, DS) . DS;
         // Make sure upload directory exists and is writable
         if (!is_dir($uploadDirectory)) {
             if (!\Filesystem::makeDirectory($uploadDirectory)) {
                 $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 $this->view->setLayout('edit');
                 $this->view->task = 'edit';
                 $this->editTask($billboard);
                 return;
             }
         }
         // Scan for viruses
         if (!\Filesystem::isSafe($billboard_image['tmp_name'])) {
             $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_FAILED_VIRUS_SCAN'));
             $this->view->setLayout('edit');
             $this->view->task = 'edit';
             $this->editTask($billboard);
             return;
         }
         if (!move_uploaded_file($billboard_image['tmp_name'], $uploadDirectory . $billboard_image['name'])) {
             $this->view->setError(Lang::txt('COM_BILLBOARDS_ERROR_FILE_MOVE_FAILED'));
             $this->view->setLayout('edit');
             $this->view->task = 'edit';
             $this->editTask($billboard);
             return;
         } else {
             // Move successful, save the image url to the billboard entry
             $billboard->set('background_img', $billboard_image['name'])->save();
         }
     }
     // Check in the billboard now that we've saved it
     $billboard->checkin();
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BILLBOARDS_BILLBOARD_SUCCESSFULLY_SAVED'));
 }
示例#5
0
 /**
  * Delete a billboard collection
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.delete', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $ids = Request::getVar('id', array());
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // Loop through the selected collections to delete
     // @TODO: maybe we should warn people if trying to delete a collection with associated billboards?
     $i = 0;
     foreach ($ids as $id) {
         $collection = Collection::oneOrFail($id);
         // Delete record
         if (!$collection->destroy()) {
             Notify::error($collection->getError());
             continue;
         }
         $i++;
     }
     // Output messsage and redirect
     if ($i) {
         Notify::success(Lang::txt('COM_BILLBOARDS_COLLECTION_SUCCESSFULLY_DELETED', $i));
     }
     $this->cancelTask();
 }