Exemplo n.º 1
0
 public function pay()
 {
     $user = JFactory::getUser();
     if ($user->guest) {
         die("Yêu cầu đăng nhập để mua");
     } else {
         $user_id = $user->id;
         $image_id = JRequest::getVar("id");
         $db = JFactory::getDBO();
         $db->setQuery("SELECT imgtitle, owner, catid, imgfilename FROM #__joomgallery WHERE id = " . $image_id);
         $image = $db->loadObject();
         $image_name = $image->imgtitle;
         $author = $image->owner;
         $price = JoomHelper::getAdditional($image_id, "price");
         $db->setQuery("INSERT INTO #__orders(user_id, image_id, image_name, author, price, buy_date) VALUES (" . $user_id . ", " . $image_id . ", '" . $image_name . "', " . $author . ", " . $price . ", NOW())");
         $db->query();
         $db->setQuery("UPDATE #__users SET balance = balance - " . (int) $price . " WHERE id = " . $user_id);
         $db->query();
         $catPath = JoomHelper::getCatPath($image->catid);
         $catPath1 = str_replace("/", DIRECTORY_SEPARATOR, $catPath);
         $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'joomgallery' . DIRECTORY_SEPARATOR . 'originals' . DIRECTORY_SEPARATOR . $catPath1 . $image->imgfilename;
         $owner = JFactory::getUser($author);
         $app = JFactory::getApplication();
         $mailfrom = $app->get('mailfrom');
         $fromname = $app->get('fromname');
         $sitename = $app->get('sitename');
         $body = "Xin chào " . $owner->name . "<br/><br/>\n\t\t\tĐây là hình mà bạn đã mua từ Khoảnh khắc Việt Nam:<br/>\n\t\t\t- Tên: " . $image_name . "<br/>\n\t\t\t- Tác giả: " . $owner->name . "<br/>\n\t\t\t- Giá: " . number_format($price, 0, ',', '.') . "<br/><br/>\n\t\t\tKhoảnh khắc Việt Nam\n\t\t\t";
         $mail = JFactory::getMailer();
         $mail->addRecipient($user->email);
         $mail->addCC($owner->email);
         $mail->setSender(array($mailfrom, $fromname));
         $mail->setSubject($sitename . ': ' . $image_name);
         $mail->setBody($body);
         $mail->IsHTML(true);
         $mail->AddAttachment($path, $image->imgfilename);
         $sent = $mail->Send();
         //Push notification to android device
         $db->setQuery("SELECT gcm_id FROM #__users_gsm WHERE user_id = " . $author . " AND login_state = 1");
         $gcms = $db->loadColumn();
         foreach ($gcms as $gcm) {
             // prep the bundle
             $msg = array('message' => 'test', 'user_id' => $user_id, 'author' => $author);
             $fields = array('registration_ids' => $gcm, 'data' => $msg);
             $headers = array('Authorization: key=AIzaSyA0r0rtbBIUXi2uU6oqRZ5TSbkeBGWYje8', 'Content-Type: application/json');
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
             $result = curl_exec($ch);
             curl_close($ch);
         }
         $this->setRedirect(JRoute::_('index.php?option=com_recharge&view=cart&layout=success'));
     }
 }
Exemplo n.º 2
0
 /**
  * Returns the URL or the path to an image
  *
  * @param   string            $type   The type of the URL or path
  * @param   string/object/int $img    Filename, database object or ID of the image
  * @param   int               $catid  The ID of the category in which the image is stored
  * @return  string            The URL or the path to the image
  * @since   1.5.5
  */
 public function getImg($type, $img, $id = 0, $catid = 0)
 {
     $types = array('thumb_path', 'thumb_url', 'img_path', 'img_url', 'orig_path', 'orig_url');
     if (!in_array($type, $types)) {
         JError::raiseError(500, JText::sprintf('Wrong image type: %s', $type));
     }
     if (!is_object($img)) {
         if (is_numeric($img)) {
             $img = $this->getImgObject($img);
         } else {
             if (!is_null($id)) {
                 $img = $this->getImgObject($id);
             }
         }
     }
     if (is_object($img)) {
         $id = $img->id;
         $catid = $img->catid;
         if ($type == 'thumb_path' || $type == 'thumb_url') {
             $img = $img->imgthumbname;
         } else {
             $img = $img->imgfilename;
         }
     }
     // Check whether the image shall be output through the PHP script or with its real path
     if (strpos($type, 'url') && ($this->_external[str_replace('_url', '', $type)] || strpos($type, 'img') !== false || strpos($type, 'orig') !== false)) {
         $type = str_replace('_url', '', $type);
         return JRoute::_('index.php?option=' . _JOOM_OPTION . '&controller=images&view=image&format=raw&type=' . $type . '&cid=' . $id);
     }
     $catpath = JoomHelper::getCatPath($catid);
     // Create the complete path
     $img = $this->{$type} . $catpath . $img;
     if (strpos($type, 'path')) {
         $img = JPath::clean($img);
     }
     return $img;
 }
Exemplo n.º 3
0
 /**
  * Checks all categories of the gallery registered in the database
  *
  * @return  void
  * @since   1.5.5
  */
 public function checkCategories()
 {
     $start = false;
     if (!$this->_mainframe->getUserState('joom.maintenance.check.checkcategories')) {
         $start = true;
         $this->_mainframe->setUserState('joom.maintenance.check.limitstart', 0);
         $this->_mainframe->setUserState('joom.maintenance.check.checkcategories', true);
     }
     $query = $this->_db->getQuery(true);
     $query->select('COUNT(c.cid)')->from(_JOOM_TABLE_CATEGORIES . ' AS c');
     $this->_db->setQuery($query);
     $total = $this->_db->loadResult();
     $refresher = new JoomRefresher(array('name' => JText::_('COM_JOOMGALLERY_MAIMAN_CHECK_CATEGORIES'), 'remaining' => $total, 'start' => $start));
     $query->clear('select')->select('c.cid, c.parent_id, c.name, c.owner, c.alias, p.cid AS parent_category, u.id AS user')->leftJoin(_JOOM_TABLE_CATEGORIES . ' AS p ON c.parent_id = p.cid')->leftJoin('#__users AS u ON c.owner = u.id');
     $types = array('thumb', 'img', 'orig');
     $table = $this->getTable('joomgallerymaintenance');
     $start = $this->_mainframe->getUserState('joom.maintenance.check.limitstart', 0);
     for ($limitstart = $start; $limitstart < $total; $limitstart += $this->limit) {
         $categories = $this->_getList($query, $limitstart, $this->limit);
         foreach ($categories as $category) {
             // Skip ROOT category
             if ($category->cid == 1) {
                 continue;
             }
             $corrupt = false;
             // Check for valid parent category
             if (!$category->parent_category) {
                 $category->parent_id = -1;
                 $corrupt = true;
             }
             // Check for valid owner
             if ($category->owner && !$category->user) {
                 $category->owner = -1;
                 $corrupt = true;
             }
             // Look for folders
             foreach ($types as $type) {
                 $folder = JPath::clean($this->_ambit->get($type . '_path') . rtrim(JoomHelper::getCatPath($category->cid), '/'), '/');
                 if (JFolder::exists($folder)) {
                     $category->{$type} = $folder;
                     // Delete the corresponding entry in orphans table
                     $delete_query = $this->_db->getQuery(true)->delete()->from(_JOOM_TABLE_ORPHANS)->where("fullpath = '" . JPath::clean($folder, '/') . "'")->where("type = 'folder'");
                     $this->_db->setQuery($delete_query);
                     $this->_db->query();
                 } else {
                     $corrupt = true;
                 }
             }
             // Check whether the image is corrupt
             if ($corrupt) {
                 // If yes, store the gathered information in the database
                 $table->reset();
                 $table->bind($category);
                 $table->id = 0;
                 $table->refid = $category->cid;
                 $table->title = $category->name;
                 $table->catid = $category->parent_id;
                 $table->type = 1;
                 $table->check();
                 $table->store();
             }
         }
         if (!$refresher->check()) {
             $this->_mainframe->setUserState('joom.maintenance.check.limitstart', $limitstart + $this->limit);
             $refresher->refresh($total - ($limitstart + $this->limit));
         }
     }
     // Prepare next step
     $query = $this->_db->getQuery(true)->select('COUNT(id)')->from(_JOOM_TABLE_ORPHANS)->where("(type = 'thumb' OR type = 'img' OR type = 'orig')");
     $this->_db->setQuery($query);
     $total = $this->_db->loadResult();
     $this->_mainframe->setUserState('joom.maintenance.check.index', 0);
     $this->_mainframe->setUserState('joom.maintenance.check.createfilesuggestions', true);
     $refresher->reset($total, true, JText::_('COM_JOOMGALLERY_MAIMAN_CREATE_FILE_SUGGESTIONS'));
     // Next step
     $refresher->refresh(0, 'createfilesuggestions');
 }
Exemplo n.º 4
0
 /**
  * Moves image into another category
  * (The given image data is only stored in the database if old and new category are different from each other)
  *
  * @param   object  $item       Holds the data of the image to move, if it's not an object we will try to retrieve the data from the database
  * @param   int     $catid_new  The ID of the category to which the image should be moved
  * @param   int     $catid_old  The ID of the old category of the image
  * @return  boolean True on success, false otherwise
  * @since   1.5.5
  */
 public function moveImage($item, $catid_new, $catid_old = 0)
 {
     jimport('joomla.filesystem.file');
     // If we just have the image ID
     if (!is_object($item)) {
         $id = intval($item);
         $item = $this->getTable('joomgalleryimages');
         $item->load($id);
         $catid_old = $item->catid;
     }
     // If the image is already in the correct category return false, no message will be set
     if ($catid_new == $catid_old) {
         return false;
     }
     $catpath_old = JoomHelper::getCatPath($catid_old);
     $catpath_new = JoomHelper::getCatPath($catid_new);
     // Database query to check if there are other images which this
     // thumbnail is assigned to and how many of them exist
     $query = $this->_db->getQuery(true)->select('COUNT(id)')->from(_JOOM_TABLE_IMAGES)->where("imgthumbname  = '" . $item->imgthumbname . "'")->where('id != ' . $item->id)->where('catid = ' . $catid_old);
     $this->_db->setQuery($query);
     $thumb_count = $this->_db->loadResult();
     // Check if thumbnail already exists in source directory and
     // if it doesn't already exist in destination directory.
     // If that's the case the file will not be copied.
     $thumb_created = false;
     $thumb_source = $this->_ambit->get('thumb_path') . $catpath_old . $item->imgthumbname;
     $thumb_dest = $this->_ambit->get('thumb_path') . $catpath_new . $item->imgthumbname;
     if (JFile::exists($thumb_dest)) {
         JError::raiseNotice(0, JText::_('COM_JOOMGALLERY_COMMON_DEST_THUMB_ALREADY_EXISTS'));
         if ($thumb_count && JFile::exists($thumb_source)) {
             JFile::delete($thumb_source);
         }
     } else {
         if (!JFile::exists($thumb_source)) {
             JError::raiseWarning(500, JText::sprintf('COM_JOOMGALLERY_COMMON_SOURCE_THUMB_NOT_EXISTS', $thumb_source));
             return false;
         } else {
             // If there is no image remaining in source directory
             // which uses the file
             if (!$thumb_count) {
                 // Move the thumbnail
                 $result = JFile::move($thumb_source, $thumb_dest);
             } else {
                 // Otherwise just copy the thumbnail in order that it remains in the source directory
                 $result = JFile::copy($thumb_source, $thumb_dest);
             }
             // If not succesful raise an error message and abort
             if (!$result) {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_COULD_NOT_MOVE_THUMB', JPath::clean($thumb_dest)));
                 return false;
             }
             // Set control variable according to the successful move/copy procedure
             $thumb_created = true;
         }
     }
     // Database query to check if there are other images which this
     // file is assigned to and how many of them exist
     $query->clear('where')->where("imgfilename = '" . $item->imgfilename . "'")->where('id != ' . $item->id)->where('catid = ' . $catid_old);
     $this->_db->setQuery($query);
     $img_count = $this->_db->loadResult();
     // Same procedure with the detail image
     // In case of error roll previous copy/move procedure back
     $img_created = false;
     $img_source = $this->_ambit->get('img_path') . $catpath_old . $item->imgfilename;
     $img_dest = $this->_ambit->get('img_path') . $catpath_new . $item->imgfilename;
     if (JFile::exists($img_dest)) {
         JError::raiseNotice(0, JText::_('COM_JOOMGALLERY_COMMON_DEST_IMG_ALREADY_EXISTS'));
         if ($img_count && JFile::exists($img_source)) {
             JFile::delete($img_source);
         }
     } else {
         if (!JFile::exists($img_source)) {
             JError::raiseWarning(500, JText::sprintf('COM_JOOMGALLERY_COMMON_SOURCE_IMG_NOT_EXISTS', $img_source));
             return false;
         } else {
             if (!$img_count) {
                 $result = JFile::move($img_source, $img_dest);
             } else {
                 $result = JFile::copy($img_source, $img_dest);
             }
             if (!$result) {
                 if ($thumb_created) {
                     if (!$thumb_count) {
                         JFile::move($thumb_dest, $thumb_source);
                     } else {
                         JFile::delete($thumb_dest);
                     }
                 }
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_COULD_NOT_MOVE_IMG', JPath::clean($img_dest)));
                 return false;
             }
             // Set control variable according to the successful move/copy procedure
             $img_created = true;
         }
     }
     // Go on with original image
     $orig_source = $this->_ambit->get('orig_path') . $catpath_old . $item->imgfilename;
     $orig_dest = $this->_ambit->get('orig_path') . $catpath_new . $item->imgfilename;
     if (JFile::exists($orig_dest)) {
         JError::raiseNotice(0, JText::_('COM_JOOMGALLERY_COMMON_DEST_ORIG_ALREADY_EXISTS'));
         if ($img_count && JFile::exists($orig_source)) {
             JFile::delete($orig_source);
         }
     } else {
         if (JFile::exists($orig_source)) {
             if (!$img_count) {
                 $result = JFile::move($orig_source, $orig_dest);
             } else {
                 $result = JFile::copy($orig_source, $orig_dest);
             }
             if (!$result) {
                 if ($thumb_created) {
                     if (!$thumb_count) {
                         JFile::move($thumb_dest, $thumb_source);
                     } else {
                         JFile::delete($thumb_dest);
                     }
                 }
                 if ($img_created) {
                     if (!$img_count) {
                         JFile::move($img_dest, $img_source);
                     } else {
                         JFile::delete($img_dest);
                     }
                 }
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_COULD_NOT_MOVE_ORIGINAL', JPath::clean($orig_dest)));
                 return false;
             }
         }
     }
     // If all folder operations for the image were successful
     // modify the database entry
     $item->catid = $catid_new;
     $item->ordering = $item->getNextOrder('catid = ' . $catid_new);
     // Make sure the record is valid
     if (!$item->check()) {
         JError::raiseWarning($item->getError());
         return false;
     }
     // Store the entry to the database
     if (!$item->store()) {
         JError::raiseWarning($item->getError());
         return false;
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * Loads the category data
  *
  * @return  boolean   True
  * @since   1.5.5
  */
 protected function _loadCategory()
 {
     if (empty($this->_category)) {
         $row = $this->getTable('joomgallerycategories');
         if ($row->load($this->_id)) {
             $row->catpath = JoomHelper::getCatPath($this->_id);
             if ($row->thumbnail) {
                 $row->catimage_src = $this->_ambit->getImg('thumb_url', $row->thumbnail, null, $this->_id);
             } else {
                 $row->catimage_src = 'media/system/images/blank.png';
             }
             if (!$this->_id) {
                 $row->published = 1;
                 $row->access = $this->_mainframe->getCfg('access');
             }
         } else {
             $row->published = 1;
             $row->access = $this->_mainframe->getCfg('access');
         }
         JPluginHelper::importPlugin('joomgallery');
         $this->_mainframe->triggerEvent('onContentPrepareData', array(_JOOM_OPTION . '.category', $row));
         $this->_category = $row;
     }
     return true;
 }
Exemplo n.º 6
0
									<th width="15%">Tên</th>
									<th width="10%">Trạng thái</th>
									<th width="7%">Mã</th>
									<th width="10%">Thể loại</th>
									<th width="10%">Độ phân giải</th>
									<th width="10%">Tag</th>
									<th width="9%" class="text-right">Giá (VND)</th>
									<th width="14%">Thao tác</th>
								</tr>
							</thead>
							<tbody>
							<?php 
foreach ($this->items as $i => $item) {
    $canView = $item->approved == 1 && $item->published && in_array($item->access, $this->_user->getAuthorisedViewLevels()) && isset($allowed_categories[$item->catid]);
    $link = JHTML::_('joomgallery.openImage', $this->_config->get('jg_detailpic_open'), $item);
    $catPath = JoomHelper::getCatPath($item->catid);
    $catPath = str_replace("/", DIRECTORY_SEPARATOR, $catPath);
    $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'joomgallery' . DIRECTORY_SEPARATOR . 'originals' . DIRECTORY_SEPARATOR . $catPath . $item->imgfilename;
    $orig_info = getimagesize($path);
    ?>
								<tr>
									<td><?php 
    echo JHTML::_('joomgallery.minithumbimg', $item, 'thumbnail', $canView, false);
    ?>
</td>
									<td><a href="<?php 
    echo $link;
    ?>
"><?php 
    echo $item->imgtitle;
    ?>
Exemplo n.º 7
0
 /**
  * Creates directories and the database entry for a category
  *
  * @param   object  $cat        Holds information about the new category
  * @param   boolean $checkOwner Determines whether the owner ID shall be checked against the existing users
  * @return  boolean True on success, false otherwise
  * @since   1.5.0
  */
 public function createCategory($cat, $checkOwner = null)
 {
     jimport('joomla.filesystem.file');
     if (is_null($checkOwner)) {
         $checkOwner = $this->checkOwner;
     }
     // Some checks
     if (!isset($cat->cid)) {
         $this->setError('Invalid category ID');
         return false;
     }
     if (!isset($cat->name)) {
         $cat->name = 'no cat name';
     }
     if (!isset($cat->alias)) {
         // Will be created later on
         $cat->alias = '';
     }
     if (!isset($cat->parent_id) || $cat->parent_id < 0) {
         $cat->parent_id = 1;
     } else {
         // If category with parent category ID 1 comes in we have
         // to set the parent ID to the newly created one because
         // category with ID 1 is the ROOT category in JoomGallery
         if ($cat->parent_id == 1) {
             $cat->parent_id = $this->newCatid;
         }
         // Main categories are children of the ROOT category
         if ($cat->parent_id == 0) {
             $cat->parent_id = 1;
         }
     }
     if (!isset($cat->description)) {
         $cat->description = '';
     }
     if (!isset($cat->ordering)) {
         $cat->ordering = 0;
     }
     if (!isset($cat->lft)) {
         $cat->lft = $cat->ordering;
     }
     if (!isset($cat->access)) {
         $cat->access = $this->_mainframe->getCfg('access');
     }
     if (!isset($cat->published)) {
         $cat->published = 0;
     }
     if (!isset($cat->hidden)) {
         $cat->hidden = 0;
     }
     if (!isset($cat->in_hidden)) {
         $cat->in_hidden = 0;
     }
     if (!isset($cat->owner) || !is_numeric($cat->owner) || $cat->owner < 1 || $checkOwner && !JUser::getTable()->load($cat->owner)) {
         $cat->owner = 0;
     }
     if (!isset($cat->password)) {
         $cat->password = '';
     }
     if (!isset($cat->thumbnail)) {
         $cat->thumbnail = 0;
     }
     if (!isset($cat->img_position)) {
         $cat->img_position = 0;
     }
     if (!isset($cat->params)) {
         $cat->params = '';
     }
     if (!isset($cat->metakey)) {
         $cat->metakey = '';
     }
     if (!isset($cat->metadesc)) {
         $cat->metadesc = '';
     }
     if (!isset($cat->exclude_toplists)) {
         $cat->exclude_toplists = 0;
     }
     if (!isset($cat->exclude_search)) {
         $cat->exclude_search = 0;
     }
     $catid_changed = false;
     if ($cat->cid == 1) {
         // Special handling for categories with ID 1 because that's the ROOT category in JoomGallery
         $cat->cid = $this->getMaxCategoryId() + 1;
         // Store the new category ID because we have to use it for the images and categories in this category
         $this->newCatid = $cat->cid;
         $this->_mainframe->setUserState('joom.migration.internal.new_catid', $this->newCatid);
         $this->writeLogfile('New ID ' . $cat->cid . ' assigned to category ' . $cat->name);
         $catid_changed = true;
     }
     // Make the category name safe
     JFilterOutput::objectHTMLSafe($cat->name);
     // If the new category should be assigned as subcategory...
     if ($cat->parent_id > 1) {
         // Save the category path of parent category in a variable
         $parentpath = JoomHelper::getCatPath($cat->parent_id);
     } else {
         // Otherwise leave it empty
         $parentpath = '';
     }
     // Creation of category path
     // Cleaning of category title with function JoomFile::fixFilename
     // so special chars are converted and underscore removed
     // affects only the category path
     $newcatname = JoomFile::fixFilename($cat->name);
     // Add an underscore and the category ID
     // affects only the category path
     $newcatname = $newcatname . '_' . $cat->cid;
     // Prepend - if exists - the parent category path
     $cat->catpath = $parentpath . $newcatname;
     // Create the paths of category for originals, pictures, thumbnails
     $cat_originalpath = JPath::clean($this->_ambit->get('orig_path') . $cat->catpath);
     $cat_detailpath = JPath::clean($this->_ambit->get('img_path') . $cat->catpath);
     $cat_thumbnailpath = JPath::clean($this->_ambit->get('thumb_path') . $cat->catpath);
     $result = array();
     if (!JFolder::exists($cat_originalpath)) {
         $result[] = JFolder::create($cat_originalpath);
         $result[] = JoomFile::copyIndexHtml($cat_originalpath);
     }
     if (!JFolder::exists($cat_detailpath)) {
         $result[] = JFolder::create($cat_detailpath);
         $result[] = JoomFile::copyIndexHtml($cat_detailpath);
     }
     if (!JFolder::exists($cat_thumbnailpath)) {
         $result[] = JFolder::create($cat_thumbnailpath);
         $result[] = JoomFile::copyIndexHtml($cat_thumbnailpath);
     }
     // Create database entry
     $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_CATEGORIES)->columns('cid, name, alias, parent_id, lft, description, access, published, hidden, in_hidden, password, owner, thumbnail, img_position, catpath, params, metakey, metadesc, exclude_toplists, exclude_search')->values((int) $cat->cid . ',' . $this->_db->quote($cat->name) . ',' . $this->_db->quote($cat->alias) . ',' . (int) $cat->parent_id . ',' . (int) $cat->lft . ',' . $this->_db->quote($cat->description) . ',' . (int) $cat->access . ',' . (int) $cat->published . ',' . (int) $cat->hidden . ',' . (int) $cat->in_hidden . ',' . $this->_db->quote($cat->password) . ',' . (int) $cat->owner . ',' . (int) $cat->thumbnail . ',' . (int) $cat->img_position . ',' . $this->_db->quote($cat->catpath) . ',' . $this->_db->quote($cat->params) . ',' . $this->_db->quote($cat->metakey) . ',' . $this->_db->quote($cat->metadesc) . ',' . (int) $cat->exclude_toplists . ',' . (int) $cat->exclude_toplists);
     $this->_db->setQuery($query);
     $result[] = $this->runQuery();
     // Create asset and alias
     $table = JTable::getInstance('joomgallerycategories', 'Table');
     $table->load($cat->cid);
     if ($table->check()) {
         $result['db'] = $table->store();
         if (!$result['db']) {
             $this->setError($table->getError(), true);
         }
     }
     if ($catid_changed) {
         // Set back category ID in the object because it may be used again later
         $cat->cid = 1;
     }
     if (!in_array(false, $result)) {
         $this->writeLogfile('Category ' . ($catid_changed ? $this->newCatid : $cat->cid) . ' created: ' . $cat->name);
         return true;
     } else {
         $this->writeLogfile(' -> Error creating category ' . ($catid_changed ? $this->newCatid : $cat->cid) . ': ' . $cat->name);
         return false;
     }
 }
Exemplo n.º 8
0
				</div><!--end. white-box-->
				
				<div class="white-box m10t  clearfix">
					{module UserMenu}
				</div><!--end. white-box-->
							
				<div class=" m10t m20b">
					<div class="title-box">
						<h2 class="title">Tác phẩm</h2>
					</div>
					<div>
						<?php 
if ($imagesStr) {
    foreach ($images as $image) {
        $link = JRoute::_('index.php?option=com_joomgallery&view=detail&id=' . $image->id);
        $catPath = JoomHelper::getCatPath($image->catid);
        $catPath1 = str_replace("/", DIRECTORY_SEPARATOR, $catPath);
        $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'joomgallery' . DIRECTORY_SEPARATOR . 'originals' . DIRECTORY_SEPARATOR . $catPath1 . $image->imgfilename;
        $orig_info = getimagesize($path);
        $owner = JFactory::getUser($image->owner);
        $ownerProfile = JUserHelper::getProfile($owner->id);
        ?>
						<div class="post-item white-box m10t">
							<div class="part-top clearfix">
								<a class="pull-left" href="#">
									<img class="avatar-30 pull-left" alt="" src="<?php 
        echo JURI::base();
        ?>
timthumb/timthumb.php?src=<?php 
        echo JURI::base() . 'media/plg_user_profilepicture/images/200/' . $ownerProfile->profilepicture['file'] . '&w=50&h=50&q=100';
        ?>
Exemplo n.º 9
0
 /**
  * Creates new folders for categories.
  *
  * @return  int/boolean Number of created folders on success, false otherwise
  * @since   1.5.5
  */
 public function create()
 {
     $cids = JRequest::getVar('cid', array(), '', 'array');
     $types = JRequest::getVar('type', array('thumb', 'img', 'orig'), '', 'array');
     if (!count($cids)) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED'));
         return false;
     }
     // Get selected category IDs
     $query = $this->_db->getQuery(true)->select('refid')->from($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->where('id IN (' . implode(',', $cids) . ')')->where('type != 0');
     $this->_db->setQuery($query);
     if (!($ids = $this->_db->loadColumn())) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $count = 0;
     foreach ($types as $type) {
         foreach ($ids as $cid) {
             // Create the folder
             $folder = $this->_ambit->get($type . '_path') . JoomHelper::getCatPath($cid);
             if (!JFolder::create($folder)) {
                 continue;
             }
             JoomFile::copyIndexHtml($folder);
             // Update maintenance table
             $query = $this->_db->getQuery(true)->update($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->set($type . ' = ' . $this->_db->q($this->_db->escape($folder)))->where('refid = ' . $cid)->where('type != 0');
             $this->_db->setQuery($query);
             if (!$this->_db->query()) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
             $count++;
         }
     }
     return $count;
 }
Exemplo n.º 10
0
 /**
  * Returns the URL or the path to an image
  *
  * @param   string            $type   The type of the URL or path
  * @param   string/object/int $img    Filename, database object or ID of the image
  * @param   int               $catid  The ID of the category in which the image is stored
  * @param   boolean           $route  True, if URLs should be parsed by the router
  * @param   int               $cropwidth  Width of cropped image if required
  * @param   int               $cropheight Height of cropped image if required
  * @param   int               $croppos    Offset position of cropping window
  * @return  string            The URL or the path to the image
  * @since   1.5.5
  */
 public function getImg($type, $img, $id = null, $catid = 0, $route = true, $cropwidth = null, $cropheight = null, $croppos = null)
 {
     $types = array('thumb_path', 'thumb_url', 'img_path', 'img_url', 'orig_path', 'orig_url');
     if (!in_array($type, $types)) {
         JError::raiseError(500, JText::sprintf('Wrong image type: %s', $type));
     }
     if (!is_object($img)) {
         if (is_numeric($img)) {
             $img = $this->getImgObject($img);
         } else {
             if (!is_null($id)) {
                 $img = $this->getImgObject($id);
             }
         }
     }
     if (is_object($img)) {
         $id = $img->id;
         $catid = $img->catid;
         if ($type == 'thumb_path' || $type == 'thumb_url') {
             $img = $img->imgthumbname;
         } else {
             $img = $img->imgfilename;
         }
     }
     // Check whether the image shall be output through the PHP script or with its real path
     if (strpos($type, 'url') && ($this->_external[str_replace('_url', '', $type)] || $this->_config->get('jg_watermark') && strpos($type, 'thumb') === false || strpos($type, 'img') !== false && !$this->_config->get('jg_use_real_paths') || strpos($type, 'orig') !== false && !$this->_config->get('jg_use_real_paths') || !is_null($cropwidth))) {
         $type = str_replace('_url', '', $type);
         $url = 'index.php?view=image&format=raw&type=' . $type . '&id=' . $id;
         if (!is_null($cropwidth)) {
             $url .= '&width=' . $cropwidth . '&height=' . $cropheight . '&pos=' . $croppos;
         }
         if ($route) {
             return JRoute::_($url);
         }
         return $url;
     }
     $catpath = JoomHelper::getCatPath($catid);
     // Create the complete path
     $img = $this->{$type} . $catpath . $img;
     if (strpos($type, 'path')) {
         $img = JPath::clean($img);
     }
     return $img;
 }
Exemplo n.º 11
0
 /**
  * Method to delete one or more categories
  *
  * @param   array $ids  IDs of categories to delete
  * @return  int   Number of successfully deleted categories, boolean false if an error occured
  * @throws  RuntimeException
  * @since   1.5.5
  */
 public function delete($ids)
 {
     if (!count($ids)) {
         throw new RuntimeException(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED'));
     }
     $delete_categories = array();
     $delete_images = array();
     $count = 0;
     $row = $this->getTable('joomgallerycategories');
     // Loop through selected categories
     foreach ($ids as $cid) {
         // Check whether we are allowed to delete this category
         if (!$this->_user->authorise('core.delete', _JOOM_OPTION . '.category.' . $cid)) {
             JLog::add(JText::sprintf('COM_JOOMGALLERY_CATMAN_ERROR_DELETE_NOT_PERMITTED', $cid), JLog::ERROR, 'jerror');
             continue;
         }
         $delete = true;
         // Check whether there are sub-categories
         // We can't use category structure here because sub-categories may have
         // already been deleted in the same request, so the structure isn't up-to-date
         $query = $this->_db->getQuery(true)->select('c.cid')->from(_JOOM_TABLE_CATEGORIES . ' AS c')->from(_JOOM_TABLE_CATEGORIES . ' AS n')->where('c.lft BETWEEN n.lft AND n.rgt')->where('n.cid = ' . $cid);
         $this->_db->setQuery($query);
         $subcategories = $this->_db->loadColumn();
         if (count($subcategories) > 1) {
             $msg = JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_CATEGORY_NOT_EMPTY_CATEGORIES', $cid);
             $this->_mainframe->enqueueMessage($msg, 'notice');
             $delete = false;
             $delete_categories = array_unique(array_merge($delete_categories, $subcategories));
         }
         // Database query to check assigned images to category
         $query = $this->_db->getQuery(true)->select('id')->from(_JOOM_TABLE_IMAGES)->where('catid IN (' . implode(',', $subcategories) . ')');
         $this->_db->setQuery($query);
         $images = $this->_db->loadColumn();
         if (count($images)) {
             $msg = JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_CATEGORY_NOT_EMPTY_IMAGES', $cid);
             $this->_mainframe->enqueueMessage($msg, 'notice');
             $delete = false;
             $delete_images = array_unique(array_merge($delete_images, $images));
             $delete_categories = array_unique(array_merge($delete_categories, array($cid)));
         }
         if ($delete) {
             $catpath = JoomHelper::getCatPath($cid);
             if (!$this->_deleteFolders($catpath)) {
                 JLog::add(JText::_('COM_JOOMGALLERY_CATMAN_MSG_ERROR_DELETING_DIRECTORIES'), JLog::WARNING, 'jerror');
             }
             $row->load($cid);
             if (!$row->delete()) {
                 throw new RuntimeException($row->getError());
             }
             $this->_mainframe->triggerEvent('onContentAfterDelete', array(_JOOM_OPTION . '.category', $row));
             // Category successfully deleted
             $count++;
         }
     }
     $this->_mainframe->setUserState('joom.categories.delete.categories', $delete_categories);
     $this->_mainframe->setUserState('joom.categories.delete.images', $delete_images);
     $cat_count = count($delete_categories);
     $img_count = count($delete_images);
     if ($cat_count || $img_count) {
         $msg = '<br />' . JText::_('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY');
         if ($img_count) {
             if ($img_count == 1) {
                 $msg .= '<br />' . JText::_('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_IMAGES_NUMBER_1');
             } else {
                 $msg .= '<br />' . JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_IMAGES_NUMBER', $img_count);
             }
         }
         if ($cat_count) {
             if ($cat_count == 1) {
                 $msg .= '<br />' . JText::_('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_CATEGORIES_NUMBER_1');
             } else {
                 $msg .= '<br />' . JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_CATEGORIES_NUMBER', $cat_count);
             }
         }
         $msg .= '<br /><br />' . JText::_('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_NOTE') . '<p/>
   <form action="index.php?option=' . _JOOM_OPTION . '&amp;controller=categories&amp;task=deletecompletely" method="post" onsubmit="if(!this.security_check.checked){return false;}">
     <span><input type="checkbox" name="security_check" value="1" /> <button class="btn">' . JText::_('COM_JOOMGALLERY_CATMAN_MSG_DELETECOMPLETELY_BUTTON_LABEL') . '</button></span>
   </form><p/>';
         $this->_mainframe->enqueueMessage($msg, 'notice');
     }
     // Reset the user state variable 'catid' for filtering in images manager
     $this->_mainframe->setUserState('joom.images.catid', 0);
     return $count;
 }
Exemplo n.º 12
0
 /**
  * Creates a new category out of the information of the given object
  *
  * @param   object  $obj  Should hold all the information about the new category
  * @param   int     The ID of the new category, false, if an error occured
  * @since   1.5.0
  */
 public function createCategory($obj)
 {
     jimport('joomla.filesystem.file');
     JLoader::register('JoomFile', JPATH_ADMINISTRATOR . '/components/' . _JOOM_OPTION . '/helpers/file.php');
     $row = JTable::getInstance('joomgallerycategories', 'Table');
     $row->bind($obj);
     if (!$row->name) {
         $this->_mainframe->enqueueMessage(JText::_('No valid category name given'), 'error');
         return false;
     }
     $row->parent_id = (int) $row->parent_id;
     if ($row->parent_id < 1) {
         $row->parent_id = 1;
     }
     // Determine location in category tree
     if (!isset($obj->ordering) || !$obj->ordering || $obj->ordering == 'first-child') {
         $row->setLocation($row->parent_id, 'first-child');
     } else {
         if ($obj->ordering == 'last-child') {
             $row->setLocation($row->parent_id, 'last-child');
         } else {
             $row->setLocation($obj->ordering, 'after');
         }
     }
     // Ensure that the data is valid
     if (!$row->check()) {
         $this->_mainframe->enqueueMessage($row->getError(), 'error');
         return false;
     }
     // Store the data in the database
     if (!$row->store()) {
         $this->_mainframe->enqueueMessage($row->getError(), 'error');
         return false;
     }
     // Now we have the ID of the new category
     // and the catpath can be built
     $row->catpath = JoomFile::fixFilename($row->name) . '_' . $row->cid;
     if ($row->parent_id > 1) {
         $row->catpath = JoomHelper::getCatPath($row->parent_id) . $row->catpath;
     }
     // So store again, but afore let's create the alias
     $row->check();
     if (!$row->store()) {
         $this->_mainframe->enqueueMessage($row->getError(), 'error');
         return false;
     }
     // Create necessary folders and files
     $origpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathoriginalimages') . $row->catpath;
     $imgpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathimages') . $row->catpath;
     $thumbpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_paththumbs') . $row->catpath;
     $result = array();
     $result[] = JFolder::create($origpath);
     $result[] = JoomFile::copyIndexHtml($origpath);
     $result[] = JFolder::create($imgpath);
     $result[] = JoomFile::copyIndexHtml($imgpath);
     $result[] = JFolder::create($thumbpath);
     $result[] = JoomFile::copyIndexHtml($thumbpath);
     if (in_array(false, $result)) {
         // Delete the just stored database entry
         $row->delete();
         return false;
     } else {
         // New category successfully created
         return $row->cid;
     }
 }
Exemplo n.º 13
0
 /**
  * HTML view display method
  *
  * @param   string  $tpl  The name of the template file to parse
  * @return  void
  * @since   1.5.5
  */
 public function display($tpl = null)
 {
     $item = $this->get('Data');
     $isNew = $item->id < 1;
     $rating = 0.0;
     // Get the form and fill the fields
     $form = $this->get('Form');
     if ($isNew) {
         // Set some field attributes for javascript validation
         $form->setFieldAttribute('detail_catid', 'required', true);
         $form->setFieldAttribute('detail_catid', 'validate', 'joompositivenumeric');
         $form->setFieldAttribute('thumb_catid', 'required', true);
         $form->setFieldAttribute('thumb_catid', 'validate', 'joompositivenumeric');
         $form->setFieldAttribute('imgfilename', 'required', true);
         $form->setFieldAttribute('imgthumbname', 'required', true);
         // Detail images
         $detail_catpath = JoomHelper::getCatPath($item->detail_catid);
         $detail_path = $this->_ambit->get('img_path') . $detail_catpath;
         $form->setFieldAttribute('imgfilename', 'directory', $detail_path);
         $imgfilename_field = $this->_findFieldByFieldName($form, 'imgfilename');
         $imagelib_field = $this->_findFieldByFieldName($form, 'imagelib2');
         // Thumbnail images
         $thumb_catpath = JoomHelper::getCatPath($item->thumb_catid);
         $thumb_path = $this->_ambit->get('thumb_path') . $thumb_catpath;
         $form->setFieldAttribute('imgthumbname', 'directory', $thumb_path);
         $imgthumbname_field = $this->_findFieldByFieldName($form, 'imgthumbname');
         $imagelib_field = $this->_findFieldByFieldName($form, 'imagelib');
     } else {
         if ($item->imgvotes > 0) {
             $rating = JoomHelper::getRating($item->id);
         }
     }
     // Bind the data to the form
     $form->bind($item);
     // Set some form fields manually
     if ($isNew) {
         // Does the original image file exist
         if ($form->getValue('imgfilename', null) == '') {
             $form->setValue('original_exists', null, JText::_('COM_JOOMGALLERY_IMGMAN_NO_IMAGE_SELECTED'));
         } else {
             if (JFile::exists($this->_ambit->getImg('orig_path', $item->imgfilename, null, $item->detail_catid))) {
                 $orig_msg = JText::_('COM_JOOMGALLERY_IMGMAN_ORIGINAL_EXIST');
                 $color = 'green';
             } else {
                 $orig_msg = JText::_('COM_JOOMGALLERY_IMGMAN_ORIGINAL_NOT_EXIST');
                 $color = 'red';
             }
             $form->setValue('original_exists', null, $orig_msg);
             $original_exists_field = $this->_findFieldByFieldName($form, 'original_exists');
             $js = "\n        window.addEvent('domready', function() {\n          \$('" . $original_exists_field->id . "').setStyle('color', '" . $color . "');\n        });";
             $this->_doc->addScriptDeclaration($js);
         }
     } else {
         // Plublished and hidden state
         if ($item->published) {
             $form->setValue('publishhiddenstate', null, $item->hidden ? JText::_('COM_JOOMGALLERY_COMMON_PUBLISHED_BUT_HIDDEN') : JText::_('COM_JOOMGALLERY_COMMON_STATE_PUBLISHED'));
         } else {
             $form->setValue('publishhiddenstate', null, JText::_('COM_JOOMGALLERY_COMMON_STATE_UNPUBLISHED'));
         }
         // Rating
         $form->setValue('rating', null, JText::sprintf('COM_JOOMGALLERY_IMGMAN_IMAGE_VOTES', $rating, $item->imgvotes));
         // Date
         $form->setValue('date', null, JHTML::_('date', $item->imgdate, JText::_('DATE_FORMAT_LC2')));
     }
     // Set image source for detail image preview
     if ($item->imgfilename) {
         if ($isNew) {
             // We have to look for the image ID fist because the image may have to be output through the script
             $id = $this->getModel()->getIdByFilename($item->imgfilename, $item->detail_catid);
             $imgsource = $this->_ambit->getImg('img_url', $id);
         } else {
             $imgsource = $this->_ambit->getImg('img_url', $item);
         }
     } else {
         $imgsource = '../media/system/images/blank.png';
     }
     $form->setValue('imagelib2', null, $imgsource);
     // Set image source for thumbnail preview
     if ($item->imgthumbname) {
         if ($isNew) {
             // We have to look for the image ID fist because the image may have to be output through the script
             $id = $this->getModel()->getIdByFilename($item->imgthumbname, $item->thumb_catid, true);
             $thumbsource = $this->_ambit->getImg('thumb_url', $id);
         } else {
             $thumbsource = $this->_ambit->getImg('thumb_url', $item);
         }
     } else {
         $thumbsource = '../media/system/images/blank.png';
     }
     $form->setValue('imagelib', null, $thumbsource);
     $this->assignRef('item', $item);
     $this->assignRef('isNew', $isNew);
     $this->assignRef('form', $form);
     $this->addToolbar();
     parent::display($tpl);
 }
Exemplo n.º 14
0
 /**
  * Batch move categories to a new category
  *
  * @param   int      $value The new parent category ID
  * @param   array    $pks   An array of category IDs
  * @return  boolean  True on success, false otherwise
  * @since   3.0
  */
 protected function batchMove($value, $pks)
 {
     $categoryId = (int) $value;
     $table = $this->getTable('joomgallerycategories');
     // Check that the parent category exists
     if ($categoryId) {
         if (!($parent_category = $table->load($categoryId))) {
             if ($error = $table->getError()) {
                 $this->setError($error);
                 return false;
             } else {
                 $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
                 return false;
             }
         }
     }
     if (!$categoryId) {
         // Check that the user has create permissions in root
         if (!$this->_user->authorise('core.create', _JOOM_OPTION)) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
             return false;
         }
         $categoryId = 1;
     } else {
         // Check that the user has create permissions
         if (!$this->_user->authorise('core.create', _JOOM_OPTION . '.category.' . $categoryId) && (!$this->_user->authorise('joom.create.inown', _JOOM_OPTION . '.category.' . $categoryId) || !$parent_category->owner || $parent_category->owner != $this->_user->get('id'))) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
             return false;
         }
     }
     foreach ($pks as $pk) {
         // Check that the category actually exists
         if (!$table->load($pk)) {
             if ($error = $table->getError()) {
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         if (!$this->_user->authorise('core.edit', _JOOM_OPTION . '.category.' . $pk) && (!$this->_user->authorise('joom.edit.own', _JOOM_OPTION . '.category.' . $pk) || !$table->owner || $table->owner != $this->_user->get('id'))) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         // New parent category ID
         $table->parent_id = $categoryId;
         // Set ordering
         $table->setLocation($categoryId, 'last-child');
         // Save old path
         $catpath_old = $table->catpath;
         JFilterOutput::objectHTMLSafe($table->name);
         // Check if special characters of catname can be replaced for a valid catpath
         // if resulting string is invalid set an error
         $catpath = JoomFile::fixFilename($table->name);
         if (JoomFile::checkValidFilename($catpath_old, $catpath) == false) {
             $this->setError(JText::_('COM_JOOMGALLERY_CATMAN_MSG_ERROR_INVALID_FOLDERNAME'));
             return false;
         }
         // Add the category ID to catpath
         $catpath .= '_' . $table->cid;
         if ($table->parent_id > 1) {
             $parent_catpath = JoomHelper::getCatPath($table->parent_id);
             $catpath = $parent_catpath . $catpath;
         }
         // Move folders, only if the catpath has changed
         if ($catpath_old != $catpath && !$this->_moveFolders($catpath_old, $catpath)) {
             $this->setError(JText::_('COM_JOOMGALLERY_CATMAN_MSG_ERROR_MOVING_FOLDERS'));
             return false;
         }
         // Update catpath in the database
         $table->catpath = $catpath;
         // Modify catpath of all sub-categories in the database
         $this->updateNewCatpath($table->cid, $catpath_old, $catpath);
         // Make sure the record is valid
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the entry to the database
         if (!$table->store()) {
             $this - setError($table->getError());
             return false;
         }
     }
     return true;
 }