Example #1
0
 public function go()
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     if (!$user->authorise('core.admin', 'com_djcatalog2')) {
         echo 'end';
         exit(0);
     }
     $id = $app->input->get('image_id', 0, 'int');
     $type = $app->input->get('type', null);
     $where_type = in_array($type, array('item', 'category', 'producer')) ? 'type="' . $type . '"' : null;
     $db = JFactory::getDbo();
     $params = JComponentHelper::getParams('com_djcatalog2');
     $query = 'select count(*) from #__djc2_images';
     if ($where_type) {
         $query .= ' where ' . $where_type;
     }
     $db->setQuery($query);
     $total = $db->loadResult();
     $query = 'select count(*) from #__djc2_images where id > ' . $id;
     if ($where_type) {
         $query .= ' and ' . $where_type;
     }
     $db->setQuery($query);
     $left = $db->loadResult();
     $query = 'select id, type, fullname, path from #__djc2_images where id > ' . $id;
     if ($where_type) {
         $query .= ' and ' . $where_type;
     }
     $query .= ' order by id asc limit 1';
     $db->setQuery($query);
     $image = $db->loadObject();
     if ($image) {
         $return = array();
         $return['id'] = $image->id;
         $return['type'] = $image->type;
         $return['name'] = $image->fullname;
         $return['total'] = $total;
         $return['left'] = $left;
         $path = empty($image->path) ? DJCATIMGFOLDER : DJCATIMGFOLDER . DS . str_replace('/', DS, $image->path);
         if (DJCatalog2ImageHelper::processImage($path, $image->fullname, $image->type, $params)) {
             $document->setMimeEncoding('application/json');
             echo json_encode($return);
         } else {
             echo 'error';
         }
     } else {
         echo 'end';
     }
     exit(0);
 }
Example #2
0
 function recreateThumbnails($cid = array())
 {
     if (count($cid)) {
         JArrayHelper::toInteger($cid);
         $cids = implode(',', $cid);
         $query = 'SELECT fullname FROM #__djc2_images' . ' WHERE item_id IN ( ' . $cids . ' )' . ' AND type=\'category\'';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $items = $this->_db->loadObjectList();
         $params = JComponentHelper::getParams('com_djcatalog2');
         foreach ($items as $item) {
             DJCatalog2ImageHelper::processImage(DJCATIMGFOLDER, $item->fullname, 'category', $params);
         }
     }
     return true;
 }