Beispiel #1
0
 /**
  * Finds the path to the requested view, accounting for overrides
  *
  * @param unknown $view            
  * @return Ambigous <boolean, string>
  */
 public function findViewFile($view)
 {
     static $paths;
     if (empty($paths)) {
         $paths = array();
     }
     $view = str_replace("\\", "/", $view);
     $pieces = \Dsc\String::split(str_replace(array("::", ":"), "|", $view));
     if (isset($paths[$view])) {
         return $paths[$view];
     }
     $paths[$view] = false;
     // 1st. Check if the requested $view has *.{lang}.php format
     $lang = $this->app->get('lang');
     $period_pieces = explode(".", $view);
     // if not, and there is a set LANGUAGE, try to find that view
     if (count($period_pieces) == 2 && !empty($lang)) {
         $lang_view = $period_pieces[0] . "." . $lang . "." . $period_pieces[1];
         if ($lang_view_found = static::findViewFile($lang_view)) {
             return $lang_view_found;
         }
     }
     // otherwise, continue doing the *.php format
     // Overrides!
     //If we are overriding the admin, lets look in an admin  folder.
     $currentTheme = $this->getCurrentTheme();
     if ($currentTheme === 'AdminTheme') {
         if ($adminPath = $this->app->get('admin_override')) {
             $dir = $this->app->get('PATH_ROOT') . $adminPath;
         } else {
             $dir = $this->app->get('PATH_ROOT') . 'apps/Admin/Overrides/';
         }
     } else {
         //else lets look inside whatever theme we are in right now.
         // an overrides folder exists in this theme, let's check for the presence of an override for the requested view file
         $dir = \Dsc\Filesystem\Path::clean($this->getThemePath($this->getCurrentTheme()) . "Overrides/");
     }
     if ($dir = \Dsc\Filesystem\Path::real($dir)) {
         if (count($pieces) > 1) {
             // we're looking for a specific view (e.g. Blog/Site/View::posts/category.php)
             $view_string = $pieces[0];
             $requested_file = $pieces[1];
             $requested_folder = dirname($pieces[1]) == "." ? null : dirname($pieces[1]);
             $requested_filename = basename($pieces[1]);
         } else {
             // (e.g. posts/category.php) that has been requested, so look for it in the overrides dir
             $view_string = null;
             $requested_file = $pieces[0];
             $requested_folder = dirname($pieces[0]) == "." ? null : dirname($pieces[0]);
             $requested_filename = basename($pieces[0]);
         }
         $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view_string . "/" . $requested_folder . "/");
         if ($path = \Dsc\Filesystem\Path::real($path)) {
             $path_pattern = $path . $requested_filename;
             if (file_exists($path_pattern)) {
                 $paths[$view] = $path_pattern;
                 return $paths[$view];
             }
         }
     }
     if (count($pieces) > 1) {
         // we're looking for a specific view (e.g. Blog/Site/View::posts/category.php)
         // $view is a specific app's view/template.php, so try to find it
         $view_string = $pieces[0];
         $requested_file = $pieces[1];
         $view_dir = $this->getViewPath($view_string);
         $path_pattern = $view_dir . $requested_file;
         if (file_exists($path_pattern)) {
             $paths[$view] = $path_pattern;
         }
     } else {
         $requested_file = $pieces[0];
         // it's a view in the format 'common/pagination.php'
         // try to find it in the registered paths
         foreach (\Dsc\ArrayHelper::get($this->dsc_theme, 'views.paths') as $view_path) {
             $path_pattern = $view_path . $requested_file;
             if (file_exists($path_pattern)) {
                 $paths[$view] = $path_pattern;
                 break;
             }
         }
     }
     return $paths[$view];
 }
Beispiel #2
0
        <?php 
$pieces = explode('?', \Dsc\Pagination::checkRoute(str_replace($BASE, '', $URI)));
$current = $pieces[0];
$list = (new \Admin\Models\Nav\Primary())->setState('filter.root', false)->setState('filter.tree', \Admin\Models\Settings::fetch()->get('admin_menu_id'))->setState('order_clause', array('tree' => 1, 'lft' => 1))->getItems();
// push the default to the beginning of the list
array_unshift($list, new \Admin\Models\Nav\Primary(array('route' => './admin', 'title' => 'Dashboard', 'icon' => 'fa-home', 'depth' => 2)));
?>
        
        <ul>
        <?php 
foreach ($list as $key => $item) {
    if (!($hasAccess = \Dsc\System::instance()->get('acl')->isAllowed($identity->role, $item->route, '*'))) {
        continue;
    }
    $class = !empty($item->class) ? $item->class : 'menu-item';
    $selected = $current == $item->route || !empty($item->base) && strpos($current, $item->base . '/') !== false || \Dsc\String::inStrings(\Dsc\ArrayHelper::getColumn($item->getDescendants(), 'route'), $current);
    if ($selected || $current == str_replace('./', '/', $item->route)) {
        $class .= " active open";
    }
    if ($item->hasDescendants()) {
        $class .= " dropdown";
    }
    if (empty($item->route)) {
        $item->route = 'javascript:void(0);';
    } elseif ($item->route[0] == '/') {
        $item->route = '.' . $item->route;
    }
    echo '<li data-depth="' . $item->getDepth() . '" class="' . $class . '">';
    // is this a module?
    // or just a regular link?
    echo '<a href="' . $item->route . '" style="">';
Beispiel #3
0
			<i class="fa fa-dashboard"></i>
			Dashboard
		</a>	
	</li>
	
	<?php 
if ($items) {
    foreach ($items as $item) {
        ?>
	<li  <?php 
        if (!empty($item->id)) {
            echo 'id="' . $item->id . '"';
        }
        ?>
   class="<?php 
        if ($current == $item->route || !empty($item->base) && strpos($current, $item->base) !== false || \Dsc\String::inStrings(\Dsc\ArrayHelper::getColumn($item->children, 'route'), $current)) {
            echo 'active';
        }
        ?>
 <?php 
        echo !empty($item->children) ? 'dropdown' : null;
        ?>
 ">
		<a href="<?php 
        echo !empty($item->children) ? 'javascript:;' : '.' . $item->route;
        ?>
">
			<?php 
        if (!empty($item->icon)) {
            ?>
<i class="<?php 
Beispiel #4
0
 /**
  * Creates an asset directly from a URL
  * and send it directly to S3
  * 
  * @param string $url
  * @param array $options
  * @throws \Exception
  */
 public static function createFromUrlToS3($url, $options = array())
 {
     $app = \Base::instance();
     $s3_options = array('clientPrivateKey' => $app->get('aws.clientPrivateKey'), 'serverPublicKey' => $app->get('aws.serverPublicKey'), 'serverPrivateKey' => $app->get('aws.serverPrivateKey'), 'expectedBucketName' => $app->get('aws.bucketname'), 'expectedMaxSize' => $app->get('aws.maxsize'), 'cors_origin' => $app->get('SCHEME') . "://" . $app->get('HOST') . $app->get('BASE'));
     if (!class_exists('\\Aws\\S3\\S3Client') || empty($s3_options['clientPrivateKey']) || empty($s3_options['serverPublicKey']) || empty($s3_options['serverPrivateKey']) || empty($s3_options['expectedBucketName']) || empty($s3_options['expectedMaxSize'])) {
         throw new \Exception('Invalid configuration settings');
     }
     $options = $options + array('width' => 460, 'height' => 308);
     $request = \Web::instance()->request($url);
     if (empty($request['body'])) {
         throw new \Exception('Could not download asset from provided URL');
     }
     $model = new static();
     $url_path = parse_url($url, PHP_URL_PATH);
     $pathinfo = pathinfo($url_path);
     $filename = $model->inputfilter()->clean($url_path);
     $buffer = $request['body'];
     $originalname = str_replace("/", "-", $filename);
     $thumb = null;
     if ($thumb_binary_data = $model->getThumb($buffer, null, $options)) {
         $thumb = new \MongoBinData($thumb_binary_data, 2);
     }
     $title = \Dsc\String::toSpaceSeparated($model->inputFilter()->clean($originalname));
     $values = array('storage' => 's3', 'contentType' => $model->getMimeType($buffer), 'md5' => md5($filename), 'thumb' => $thumb, 'url' => null, "source_url" => $url, "filename" => $filename, 'title' => $title);
     $model->bind($values);
     // these need to happen after the bind
     $model->slug = $model->generateSlug();
     $model->_id = new \MongoId();
     /**
      * Push to S3
      */
     $bucket = $app->get('aws.bucketname');
     $s3 = \Aws\S3\S3Client::factory(array('key' => $app->get('aws.serverPublicKey'), 'secret' => $app->get('aws.serverPrivateKey')));
     $key = (string) $model->_id;
     $res = $s3->putObject(array('Bucket' => $bucket, 'Key' => $key, 'Body' => $buffer, 'ContentType' => $model->contentType));
     $s3->waitUntil('ObjectExists', array('Bucket' => $bucket, 'Key' => $key));
     if (!$s3->doesObjectExist($bucket, $key)) {
         throw new \Exception("Upload to Amazon S3 failed");
     }
     $objectInfoValues = $s3->headObject(array('Bucket' => $bucket, 'Key' => $key))->getAll();
     /**
      * END Push to S3
      */
     $model->url = $s3->getObjectUrl($bucket, $key);
     $model->s3 = array_merge(array(), (array) $model->s3, array('bucket' => $bucket, 'key' => $key, 'uuid' => (string) $model->_id)) + $objectInfoValues;
     return $model->save();
 }
Beispiel #5
0
 public function replaceTraditional()
 {
     $app = \Base::instance();
     $files_path = $app->get('TEMP') . "files";
     $chunks_path = $app->get('TEMP') . "chunks";
     if (!file_exists($chunks_path)) {
         mkdir($chunks_path, \Base::MODE, true);
     }
     if (!file_exists($files_path)) {
         mkdir($files_path, \Base::MODE, true);
     }
     $uploader = new \Fineuploader\Traditional\Handler();
     // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
     $uploader->allowedExtensions = array();
     // all files types allowed by default
     // Specify max file size in bytes.
     $uploader->sizeLimit = 10 * 1024 * 1024;
     // default is 10 MiB
     // Specify the input name set in the javascript.
     $uploader->inputName = "qqfile";
     // matches Fine Uploader's default inputName value by default
     // If you want to use the chunking/resume feature, specify the folder to temporarily save parts.
     $uploader->chunksFolder = $chunks_path;
     $method = $_SERVER["REQUEST_METHOD"];
     if ($method == "POST") {
         header("Content-Type: text/plain");
         // Call handleUpload() with the name of the folder, relative to PHP's getcwd()
         $result = $uploader->handleUpload($files_path);
         // To return a name used for uploaded file you can use the following line.
         $result["uploadName"] = $uploader->getUploadName();
         $result["originalName"] = $uploader->getName();
         // was upload successful?
         if (!empty($result['success'])) {
             // OK, we have the file in the tmp folder, let's now fire up the assets model and save it to Mongo
             $slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'string');
             $asset = $this->getModel()->setState('filter.slug', $slug)->getItem();
             if (empty($asset->id)) {
                 throw new \Exception('Invalid Asset');
             }
             // The file's location in the File System
             $filename = $result["uploadName"];
             $pathinfo = pathinfo($filename);
             $buffer = file_get_contents($files_path . "/" . $filename);
             $originalname = $result["originalName"];
             $pathinfo_original = pathinfo($originalname);
             $values = array('storage' => 'gridfs', 'contentType' => $asset->getMimeType($buffer), 'md5' => md5_file($files_path . "/" . $filename), 'url' => null, "title" => \Dsc\String::toSpaceSeparated($asset->inputfilter()->clean($originalname)), "filename" => $originalname);
             if (empty($values['title'])) {
                 $values['title'] = $values['md5'];
             }
             // save the file
             $asset = $asset->replace($buffer, $values);
             $result["asset_id"] = (string) $asset->id;
             $result["slug"] = $asset->{'slug'};
         }
         echo json_encode($result);
     } else {
         header("HTTP/1.0 405 Method Not Allowed");
     }
 }
Beispiel #6
0
 public function handleTraditional()
 {
     $app = \Base::instance();
     $files_path = $app->get('TEMP') . "files";
     $chunks_path = $app->get('TEMP') . "chunks";
     if (!file_exists($chunks_path)) {
         mkdir($chunks_path, \Base::MODE, true);
     }
     if (!file_exists($files_path)) {
         mkdir($files_path, \Base::MODE, true);
     }
     $uploader = new \Fineuploader\Traditional\Handler();
     $name = $uploader->getName();
     $parts = explode('_', $name);
     $model_number = $parts[0];
     $order = (int) explode('.', $parts[1])[0];
     //LOOK FOR A PRODUCT
     $product = (new \Shop\Models\Products())->setCondition('tracking.model_number', $model_number)->getItem();
     if (empty($product->id)) {
         $result = [];
         $result['success'] = false;
         $result['error'] = 'Product not found looking for tracking.model_number = ' . $model_number;
         $result['preventRetry'] = true;
         echo json_encode($result);
         exit;
     }
     // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
     $uploader->allowedExtensions = array();
     // all files types allowed by default
     // Specify max file size in bytes.
     $uploader->sizeLimit = 10 * 1024 * 1024;
     // default is 10 MiB
     // Specify the input name set in the javascript.
     $uploader->inputName = "qqfile";
     // matches Fine Uploader's default inputName value by default
     // If you want to use the chunking/resume feature, specify the folder to temporarily save parts.
     $uploader->chunksFolder = $chunks_path;
     $method = $_SERVER["REQUEST_METHOD"];
     if ($method == "POST") {
         header("Content-Type: text/plain");
         // Call handleUpload() with the name of the folder, relative to PHP's getcwd()
         $result = $uploader->handleUpload($files_path);
         // To return a name used for uploaded file you can use the following line.
         $result["uploadName"] = $uploader->getUploadName();
         $result["originalName"] = $uploader->getName();
         // was upload successful?
         if (!empty($result['success'])) {
             // OK, we have the file in the tmp folder, let's now fire up the assets model and save it to Mongo
             $model = new \Assets\Admin\Models\Assets();
             $db = $model->getDb();
             $grid = $model->collectionGridFS();
             // The file's location in the File System
             $filename = $result["uploadName"];
             $pathinfo = pathinfo($filename);
             $buffer = file_get_contents($files_path . "/" . $filename);
             $originalname = $result["originalName"];
             $pathinfo_original = pathinfo($originalname);
             $thumb = null;
             if ($thumb_binary_data = $model->getThumb($buffer, $pathinfo['extension'])) {
                 $thumb = new \MongoBinData($thumb_binary_data, 2);
             }
             $values = array('storage' => 'gridfs', 'contentType' => $model->getMimeType($buffer), 'md5' => md5_file($files_path . "/" . $filename), 'thumb' => $thumb, 'url' => null, "title" => \Dsc\String::toSpaceSeparated($model->inputfilter()->clean($originalname)), "filename" => $originalname);
             if (empty($values['title'])) {
                 $values['title'] = $values['md5'];
             }
             // save the file
             if ($storedfile = $grid->storeFile($files_path . "/" . $filename, $values)) {
                 $model->load(array('_id' => $storedfile));
                 $model->bind($values);
                 $model->{'slug'} = $model->generateSlug();
                 $model->{'type'} = 'shop.assets';
                 $model->save();
             }
             // $storedfile has newly stored file's Document ID
             $result["asset_id"] = (string) $storedfile;
             $result["slug"] = $model->{'slug'};
             \Dsc\Queue::task('\\Assets\\Models\\Storage\\CloudFiles::gridfstoCDN', array($result['asset_id'], '/product_images/' . $model_number . '/'));
         }
         $product->addImage($model->{'slug'}, $order);
         echo json_encode($result);
     } else {
         header("HTTP/1.0 405 Method Not Allowed");
     }
 }