function display($tpl = null) { jimport( 'joomla.session.session' ); $currentSession = JSession::getInstance('none',array()); $currentSession->set("search_fields",""); $currentSession->set("searchfieldscatid",0); $currentSession->set("searchfieldssql"," 1 "); $currentSession->set("tsearch","",'adsmanager'); $app = JFactory::getApplication(); $pathway = $app->getPathway(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $contentmodel =$this->getModel( "content" ); $catmodel =$this->getModel( "category" ); $configurationmodel =$this->getModel( "configuration" ); // Get the parameters of the active menu item $menus = $app->getMenu(); $menu = $menus->getActive(); $conf = $configurationmodel->getConfiguration(); $rootid = JRequest::getInt('rootid',0); $cats = $catmodel->getFlatTree(true, true, $nbContents, 'read',$rootid); $this->assignRef('cats',$cats); $this->assignRef('conf',$conf); $document->setTitle( JText::_('ADSMANAGER_PAGE_TITLE')); $general = new JHTMLAdsmanagerGeneral(0,$conf,$user); $this->assignRef('general',$general); $conf = $configurationmodel->getConfiguration(); $nbimages = $conf->nb_images; if (function_exists("getMaxPaidSystemImages")) { $nbimages += getMaxPaidSystemImages(); } $this->assignRef('nbimages',$nbimages); $nb_cols = $conf->nb_last_cols; $nb_rows = $conf->nb_last_rows; $contents = $contentmodel->getLatestContents($nb_cols*$nb_rows,0,"no",$rootid); $this->assignRef('contents',$contents); parent::display($tpl); }
function bindContent($post, $files, $conf, $model, $plugins) { $app = JFactory::getApplication(); $this->bind($post); if ($this->id == 0) { $this->new_ad = true; } else { $query = "SELECT content FROM #__adsmanager_pending_ads WHERE contentid = {$this->id}"; $this->_db->setQuery($query); $currentpendingchanges = $this->_db->loadResult(); if ($currentpendingchanges != null) { $currentpendingchanges = @json_decode($currentpendingchanges); if (isset($currentpendingchanges->published)) { $this->published = $currentpendingchanges->published; } if (isset($currentpendingchanges->new_ad)) { $this->new_ad = $currentpendingchanges->new_ad; } } } $this->data = array(); $this->errors = array(); if (function_exists("getMaxCats")) { $maxcats = getMaxCats($conf->nbcats); } else { $maxcats = $conf->nbcats; } if ($maxcats > 1) { $selected_cats = $post["selected_cats"]; if (!is_array($selected_cats)) { $c = array(); $c[0] = $selected_cats; $selected_cats = $c; } if (count($selected_cats) > $maxcats) { $selected_cats = array_slice($selected_cats, 0, $maxcats); } $this->data['categories'] = $selected_cats; } else { $category = $post["category"]; $this->data['categories'] = array(); $this->data['categories'][0] = intval($category); } //get fields $this->_db->setQuery("SELECT * FROM #__adsmanager_fields WHERE published = 1"); $fields = $this->_db->loadObjectList(); foreach ($fields as $key => $field) { $fields[$key]->options = json_decode($fields[$key]->options); } if ($this->_db->getErrorNum()) { $this->errors[] = $this->_db->stderr(); return false; } $query = "UPDATE #__adsmanager_ads "; $bannedwords = str_replace("\r", "", $conf->bannedwords); $bannedwords = explode("\n", $bannedwords); $replaceword = $conf->replaceword; $data['fields'] = array(); foreach ($fields as $field) { //If admin edit only should leave the loop otherwise value is reseted to empty string if ($app->isAdmin() == false && @$field->options->edit_admin_only == 1) { continue; } if ($field->type == "multiselect") { $value = JRequest::getVar($field->name, array()); $this->data['fields'][$field->name] = $value; } else { if ($field->type == "multicheckbox" || $field->type == "multicheckboximage") { $value = $value = JRequest::getVar($field->name, array()); $this->data['fields'][$field->name] = $value; } else { if ($field->type == "file") { if (isset($files[$field->name]) and !$files[$field->name]['error']) { jimport('joomla.filesystem.file'); if (is_file(JPATH_ROOT . "/images/com_adsmanager/files/" . $field->name)) { JFile::delete(JPATH_ROOT . "/images/com_adsmanager/files/" . $field->name); } $filename = $files[$field->name]['name']; $extension = JFile::getExt($filename); $name = md5(rand(1, 100000) . $filename); if (strpos($extension, "php") !== false) { $extension = 'txt'; } $filename = $name . "." . $extension; JFile::upload($files[$field->name]['tmp_name'], JPATH_ROOT . "/images/com_adsmanager/files/" . $filename); $this->data['fields'][$field->name] = $filename; } else { if (JRequest::getInt("delete_" . $field->name) == 1) { if (is_file(JPATH_ROOT . "/images/com_adsmanager/files/" . $field->name)) { JFile::delete(JPATH_ROOT . "/images/com_adsmanager/files/" . $field->name); } $this->data['fields'][$field->name] = ""; } } } else { if ($field->type == "editor") { $value = JRequest::getVar($field->name, '', 'post', 'string', JREQUEST_ALLOWHTML); $this->data['fields'][$field->name] = $this->replaceBannedWords($value, $bannedwords, $replaceword); } else { if ($field->type == "price") { $value = JRequest::getVar($field->name, ''); $value = str_replace(',', '.', $value); $value = str_replace(' ', '', $value); $this->data['fields'][$field->name] = $value; } else { if (isset($plugins[$field->type])) { $value = $plugins[$field->type]->onFormSave($this, $field); if ($value !== null) { $this->data['fields'][$field->name] = $value; } } else { $value = JRequest::getVar($field->name, ''); $this->data['fields'][$field->name] = $this->replaceBannedWords($value, $bannedwords, $replaceword); } } } } } } } $this->data['images'] = array(); $this->data['delimages'] = array(); $current_images = json_decode($this->images); if ($current_images == null) { $current_images = array(); } $image_index = 0; $pending = JRequest::getInt('pending', 0); if ($pending && count($currentpendingchanges->images) > 0) { foreach ($currentpendingchanges->images as $img) { $this->data['images'][] = $img; if ($img->index > $image_index) { $image_index = $img->index; } } } $deleted_images = JRequest::getVar("deleted_images", ""); $deleted_images = explode(',', $deleted_images); foreach ($current_images as $i => $img) { if (in_array($img->index, $deleted_images)) { $this->data['delimages'][] = $img; } else { if ($img->index > $image_index) { $image_index = $img->index; } } } foreach ($this->data['images'] as $i => $img) { if (in_array($img->index, $deleted_images)) { if (is_file(JPATH_ROOT . "/images/com_adsmanager/ads/waiting/" . $img->image)) { JFile::delete(JPATH_ROOT . "/images/com_adsmanager/ads/waiting/" . $img->image); } /* if(is_file(JPATH_ROOT."/images/com_adsmanager/ads/waiting/".$img->thumbnail)) { JFile::delete(JPATH_ROOT."/images/com_adsmanager/ads/waiting/".$img->thumbnail); } if(is_file(JPATH_ROOT."/images/com_adsmanager/ads/waiting/".$img->medium)) { @JFile::delete(JPATH_ROOT."/images/com_adsmanager/ads/waiting/".$img->medium); }*/ unset($this->data['images'][$i]); } } $nb_images = count($current_images) - count($this->data['delimages']); $nbMaxImages = $conf->nb_images; if (function_exists("getMaxPaidSystemImages")) { $nbMaxImages += getMaxPaidSystemImages(); } $uploader_count = JRequest::getInt('imagesupload_count', 0); $targetDir = JPATH_ROOT . '/images/com_adsmanager/ads/uploaded'; $dir = JPATH_ROOT . "/images/com_adsmanager/ads/waiting/"; $orderlisttmp = explode(',', JRequest::getString('orderimages', "")); $orderlist = array(); foreach ($orderlisttmp as $value) { $orderlist[] = str_replace('li_img_', '', $value); } for ($i = 0; $i < $uploader_count && $nb_images < $nbMaxImages; $i++) { $uploader_tmpname = JRequest::getString('imagesupload_' . $i . '_tmpname', 0); $uploader_id = JRequest::getString('imagesupload_' . $i . '_id', 0); $uploader_name = JRequest::getString('imagesupload_' . $i . '_name', 0); $uploader_status = JRequest::getString('imagesupload_' . $i . '_status', 0); $tmpfile = sha1(microtime(true) . mt_rand(10000, 90000)) . ".jpg"; $thumb_tmpfile = sha1(microtime(true) . mt_rand(10000, 90000)) . ".jpg"; $medium_tmpfile = sha1(microtime(true) . mt_rand(10000, 90000)) . ".jpg"; //var_dump($targetDir."/".$uploader_tmpname); //var_dump($uploader_status); if ($uploader_status == "done" && file_exists($targetDir . "/" . $uploader_tmpname)) { try { $error = $model->createImageAndThumb($targetDir . "/" . $uploader_tmpname, $tmpfile, $thumb_tmpfile, $conf->max_width, $conf->max_height, $conf->max_width_t, $conf->max_height_t, $conf->tag, $dir, $uploader_name, $conf->max_width_m, $conf->max_height_m, $medium_tmpfile); if (is_file($targetDir . "/" . $uploader_tmpname)) { JFile::delete($targetDir . "/" . $uploader_tmpname); } if ($error != null) { $this->errors[] = $error; } else { $image_index++; $nb_images++; $newimg = new stdClass(); $newimg->index = $image_index; $newimg->image = $tmpfile; $newimg->thumbnail = $thumb_tmpfile; $newimg->medium = $medium_tmpfile; $this->data['images'][] = $newimg; //echo $uploader_id."<br/>"; foreach ($orderlist as $key => $val) { if ($val == $uploader_id) { $orderlist[$key] = $image_index; } } } } catch (Exception $e) { if (is_file($targetDir . "/" . $uploader_tmpname)) { JFile::delete($targetDir . "/" . $uploader_tmpname); } $this->errors[] = $e->getMessage(); } } } $this->data['orderimages'] = $orderlist; $this->update_validation = @$conf->update_validation; $app = JFactory::getApplication(); if ($app->isAdmin() == false && $this->id == 0) { $this->date_created = date("Y-m-d H:i:s"); $delta = $conf->ad_duration; if ($delta == 0) { $this->expiration_date = null; } else { $this->expiration_date = date("Y-m-d H:i:s", time() + $delta * 24 * 3600); } if ($conf->auto_publish == 1) { $this->published = 1; } else { $this->published = 0; } } else { if ($this->id != 0) { if ($this->update_validation) { $this->published = 0; } } } if ($this->id == 0) { if (!isset($conf->publication_date) || $conf->publication_date == 0) { $this->publication_date = date("Y-m-d H:i:s"); } else { $this->publication_date = $this->publication_date . ' 00:00:00'; } if ($app->isAdmin() == false) { $this->expiration_date = date("Y-m-d H:i:s", strtotime($this->publication_date) + $delta * 24 * 3600); } } else { if ($app->isAdmin() == true) { $this->publication_date = $this->publication_date . ' 00:00:00'; } } if (count($this->errors) > 0) { return false; } else { return true; } }
function getPendingContent($contentid) { #__adsmanager_pending_ads WHERE contentid = ".(int) $sql = " SELECT a.*,u.username as user,u.name as fullname FROM #__adsmanager_pending_ads as a " . " LEFT JOIN #__users as u ON a.userid = u.id " . " WHERE a.contentid = " . (int) $contentid; $this->_db->setQuery($sql); $pending = $this->_db->loadObject(); if ($pending == null) { return null; } $pending->data = json_decode($pending->content); $content = new stdClass(); $content->id = $contentid; $content->userid = $pending->userid; if (isset($pending->data->fields)) { foreach ($pending->data->fields as $name => $value) { $content->{$name} = $value; } } $content->user = $pending->user; $content->fullname = $pending->fullname; $content->pending = 1; $this->_db->setQuery(" SELECT * FROM #__adsmanager_config "); $conf = $this->_db->loadObject(); $nbimages = $conf->nb_images; if (function_exists("getMaxPaidSystemImages")) { $nbimages += getMaxPaidSystemImages(); } $baseurl = JURI::base(); $content->catsid = array(); $content->cats = array(); if (is_array($pending->data->categories)) { foreach ($pending->data->categories as $cat) { $content->catsid[] = $cat; $content->catid = $cat; $category = new stdClass(); $category->catid = $cat; $content->cats[] = $category; } } else { $content->catid = $pending->data->categories; $content->catsid[] = $pending->data->categories; $category = new stdClass(); $category->catid = $cat; $content->cats[] = $category; } $images = array(); if (isset($pending->data->images)) { foreach ($pending->data->images as $image) { $images[] = $image; } } if (isset($pending->data->paid->images)) { foreach ($pending->data->paid->images as $image) { $images[] = $image; } } $content->images = $images; if ($pending->data->paid->featured) { $content->featured = $pending->data->paid->featured; } if ($pending->data->paid->top) { $content->top = $pending->data->paid->top; } if ($pending->data->paid->highlight) { $content->highlight = $pending->data->paid->highlight; } $content->duration = @$pending->data->duration; return $content; }
function getPendingContent($contentid) { #__adsmanager_pending_ads WHERE contentid = ".(int) $sql = " SELECT a.*,u.username as user,u.name as fullname FROM #__adsmanager_pending_ads as a " . " LEFT JOIN #__users as u ON a.userid = u.id " . " WHERE a.contentid = " . (int) $contentid; $this->_db->setQuery($sql); $pending = $this->_db->loadObject(); if ($pending == null) { return null; } $pending->data = json_decode($pending->content); $content = new stdClass(); $content->id = $contentid; $content->userid = $pending->userid; if (isset($pending->data->fields)) { foreach ($pending->data->fields as $name => $value) { $content->{$name} = $value; } } $content->user = $pending->user; $content->fullname = $pending->fullname; $content->pending = 1; $conf = TConf::getConfig(); $nbimages = $conf->nb_images; if (function_exists("getMaxPaidSystemImages")) { $nbimages += getMaxPaidSystemImages(); } $baseurl = JURI::base(); $content->catsid = array(); $content->cats = array(); if (is_array($pending->data->categories)) { foreach ($pending->data->categories as $cat) { $content->catsid[] = $cat; $content->catid = $cat; $category = new stdClass(); $category->catid = $cat; $content->cats[] = $category; } } else { $content->catid = $pending->data->categories; $content->catsid[] = $pending->data->categories; $category = new stdClass(); $category->catid = $cat; $content->cats[] = $category; } $images = array(); $sql = "SELECT images FROM #__adsmanager_ads as a WHERE a.id = " . (int) $contentid; $this->_db->setQuery($sql); $existingimages = $this->_db->loadResult(); $existingimages = json_decode($existingimages); if ($existingimages != null) { foreach ($existingimages as $image) { $images[] = $image; } } if (isset($pending->data->delimages) && count($pending->data->delimages) > 0) { $indexes = array(); foreach ($pending->data->delimages as $img) { $indexes[] = $img->index; } foreach ($images as $i => $img) { if (in_array($img->index, $indexes)) { unset($images[$i]); } } } if (isset($pending->data->images)) { foreach ($pending->data->images as $image) { $images[] = $image; } } $content->images = $images; $dir = JPATH_ROOT . "/images/com_adsmanager/ads/waiting/"; foreach ($content->images as $key => $image) { $src = $dir . $image->image; if (is_file($src)) { $content->images[$key]->tmp = 1; } else { $content->images[$key]->tmp = 0; } } $orderlist = $pending->data->orderimages; $newlistimages = array(); foreach ($orderlist as $o) { foreach ($content->images as $image) { if ($image->index == $o) { $newlistimages[] = $image; } } } $content->images = $newlistimages; $content->pendingdata = $pending->data; if ($pending->data->paid->featured) { $content->featured = $pending->data->paid->featured; } if ($pending->data->paid->top) { $content->top = $pending->data->paid->top; } if ($pending->data->paid->highlight) { $content->highlight = $pending->data->paid->highlight; } $content->duration = @$pending->data->duration; return $content; }
* @license GNU/GPL */ // Check to ensure this file is within the rest of the framework defined('JPATH_BASE') or die(); if (isset($this->warning_text)) echo '<div class="alert alert-warning">'.htmlspecialchars($this->warning_text)."</div>"; if (isset($this->error_text)) echo '<div class="alert alert-warning">'.htmlspecialchars($this->error_text)."</div>"; echo JText::_('ADSMANAGER_RULESREAD'); $app = JFactory::getApplication(); $nbimages = $this->conf->nb_images; if (PAIDSYSTEM) { $nbimages += getMaxPaidSystemImages(); } if ($nbimages > 0) { $withImages = true; } else { $withImages = false; } $without_page_reload = 1; if (PAIDSYSTEM) { $without_page_reload = @getPaidSystemConfig()->without_page_reload; } $target = TRoute::_("index.php?option=com_adsmanager&task=save"); JHtml::_('behavior.framework'); $document = JFactory::getDocument();