Ejemplo n.º 1
0
/**
 * retrieve an ad
 *
 * @return array ad details
 */
function ClassifiedAds_adminAdGet()
{
    $id = (int) $_REQUEST['id'];
    return ClassifiedAds::get($id, true);
}
Ejemplo n.º 2
0
/**
 * frontend of the classified ads thing
 *
 * @param object $PAGEDATA the page object
 *
 * @return html
 */
function ClassifiedAds_frontend($PAGEDATA)
{
    global $unused_uri;
    $html = $PAGEDATA->render();
    $bits = false;
    if ($unused_uri == '') {
        $cid = 0;
    } else {
        $bits = explode('/', preg_replace('/\\/$/', '', $unused_uri));
        $cid = ClassifiedAds_getCategoryId($bits);
    }
    $sql = 'select name from classifiedads_categories where id=' . $cid;
    WW_addInlineScript('var classifiedads_categoryId=' . $cid . ', classifiedads_categoryName="' . addslashes(dbOne($sql, 'name')) . '"' . ', classifiedads_paypal="' . $PAGEDATA->vars['classified-ads-paypal'] . '";');
    $html = '<div id="classifiedads-wrapper">';
    // { breadcrumbs
    if ($bits) {
        $html .= '<div class="breadcrumbs">' . ClassifiedAds_getBreadcrumbs($PAGEDATA, $bits);
        if ($cid) {
            $html .= ' <span class="divider">&raquo;</span>' . ' <button class="classifiedads-advertise-button">' . 'Advertise Here</button>';
            WW_addScript('classified-ads/frontend/advertise.js');
        }
        $html .= '</div>';
    }
    // }
    if ($bits && preg_match('/^[0-9]+-.*/', $bits[count($bits) - 1])) {
        $ad_id = (int) preg_replace('/[^0-9].*/', '', $bits[count($bits) - 1]);
        $ad = ClassifiedAds::get($ad_id);
        $html .= '<div id="classifiedads-single">' . '<h2>' . htmlspecialchars($ad['title']) . '</h2>' . '<table id="classifiedads-ad-details"><tr>' . '<td class="classifiedads-creation-date">Posted: ' . Core_dateM2H($ad['creation_date']) . '</td>' . '<td class="classifiedads-location">Location: ' . htmlspecialchars($ad['location']) . '</td>' . '<td class="classifiedads-cost">Cost: €' . htmlspecialchars($ad['cost']) . '</td></tr></table>';
        $images = array();
        $dir = '/userfiles/' . $ad['user_id'] . '/classified-ads/' . $ad['id'];
        if (file_exists(USERBASE . '/f' . $dir)) {
            $files = new DirectoryIterator(USERBASE . '/f' . $dir);
            foreach ($files as $f) {
                if ($f->isDot() || $f->isDir()) {
                    continue;
                }
                $images[] = '<a href="/f' . $dir . '/' . $f->getFilename() . '" target="popup">' . '<img src="/a/f=getImg/w=128/h=128' . $dir . '/' . $f->getFilename() . '"' . ' style="max-width:128px;max-height:128px"/></a>';
            }
        }
        $html .= '<p class="classified-ads-body">' . nl2br(htmlspecialchars($ad['body'])) . '</p>' . join('', $images);
        $html .= '<table class="classifiedads-contact"><tr>';
        if ($ad['phone']) {
            $html .= '<td>Phone: ' . htmlspecialchars($ad['phone']) . '</td>';
        }
        /*		if ($ad['email']) {
        			$html.='<td>Email: <a href="#" class="classified-ads-email"'
        				.' data-ad-id="'.$ad['id'].'">click to send</a></td>';
        		} */
        $html .= '</tr></table>';
        $html .= '</div>';
    } else {
        // show sub-categories and ads
        // { sub-categories
        $subcats = dbAll('select id, icon, name from classifiedads_categories where parent=' . $cid . ' order by name');
        if (count($subcats)) {
            $html .= '<div id="classifiedads-subcats">' . '<h2>Categories</h2><ul>';
            foreach ($subcats as $cat) {
                $url = ClassifiedAds_getCategoryUrl($cat['id']);
                $html .= '<li>' . '<a href="' . $url . '">';
                if ($cat['icon']) {
                    $html .= '<img src="/a/f=getImg/' . $cat['icon'] . '/w=32/h=32"/>';
                }
                $html .= htmlspecialchars($cat['name']);
                $html .= '</a></li>';
            }
            $html .= '</div>';
        }
        // }
        // { ads
        $subcatsRecursive = ClassifiedAds_getCategoryIdsRecursive($cid);
        $ads = ClassifiedAds::getByCategories($subcatsRecursive);
        $html .= '<table id="classifiedads-ads">' . '<thead><tr><th colspan="2">Title</th><th>Location</th><th>Posted</th>' . '<th>Price</th></tr></thead><tbody>';
        $today = date('Y-m-d');
        foreach ($ads as $ad) {
            if ($ad['expiry_date'] < $today) {
                dbQuery('delete from classifiedads_ad where id=' . $ad['id']);
                Core_cacheClear('classifiedads_ad');
                continue;
            }
            $url = ClassifiedAds_getCategoryUrl($ad['category_id']) . '/' . $ad['id'] . '-' . preg_replace('/[^a-z0-9A-Z]/', '-', $ad['title']);
            $img = '';
            $adDir = '/userfiles/' . $ad['user_id'] . '/classified-ads/' . $ad['id'];
            $dir = USERBASE . '/f' . $adDir;
            if (file_exists($dir)) {
                $files = new DirectoryIterator($dir);
                foreach ($files as $f) {
                    if (!$f->isDot()) {
                        $img = '<img style="max-width:64px;max-height:64px;" src="/a/f=getImg/w=64/h=64' . $adDir . '/' . $f->getFilename() . '"/>';
                        break;
                    }
                }
            }
            $html .= '<tr class="ad-top-details"><td rowspan="2">' . $img . '</td><td><a href="' . $url . '">' . htmlspecialchars($ad['title']) . '</a></td>' . '<td class="location">' . htmlspecialchars($ad['location']) . '</td>' . '<td class="posted">' . Core_dateM2H($ad['creation_date']) . '</td>' . '<td class="price">€' . htmlspecialchars($ad['cost']) . '</td>' . '</tr><tr class="ad-bottom-details">' . '<td colspan="4">' . $ad['excerpt'] . '</td></tr>';
        }
        $html .= '</tbody></table>';
        // }
    }
    $html .= '</div>';
    $html .= @$PAGEDATA->vars['footer'];
    WW_addCSS('/ww.plugins/classified-ads/frontend/style.css');
    WW_addScript('/j/uploader.js');
    return $html;
}