Ejemplo n.º 1
0
$p->set_var('LANG_FILESIZE', _MD_FILESIZE);
$pos = MBYTE_strpos($url, ':');
if ($pos === false) {
    $p->set_var('file_size', PrettySize($size));
} else {
    if ($size != 0) {
        $p->set_var('file_size', PrettySize($size));
    } else {
        $p->set_var('file_size', 'Remote');
    }
}
$p->set_var('homepage_url', $homepage);
$p->set_var('LANG_HOMEPAGE', _MD_HOMEPAGE);
$p->set_var('homepage', $homepage);
if ($comments) {
    USES_lib_comments();
    $commentCount = DB_count($_TABLES['comments'], 'sid', "fileid_{$lid}");
    $recentPostMessage = _MD_COMMENTSWANTED;
    if ($commentCount > 0) {
        $result4 = DB_query("SELECT cid, UNIX_TIMESTAMP(date) AS day,username FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = 'fileid_{$lid}' ORDER BY date desc LIMIT 1");
        $C = DB_fetchArray($result4);
        $dt->setTimestamp($C['day']);
        $recentPostMessage = $LANG01[27] . ': ' . $dt->format($_CONF['daytime'], true) . ' ' . $LANG01[104] . ' ' . $C['username'];
    } else {
        $commentCount = 0;
    }
    $comment_link = CMT_getCommentLinkWithCount('filemgmt', $lid, $_CONF['site_url'] . '/filemgmt/index.php?id=' . $lid, $commentCount, 1);
    $p->set_var('comment_link', $comment_link['link_with_count']);
    $p->set_var('show_comments', 'true');
} else {
    $p->set_var('show_comments', 'none');
Ejemplo n.º 2
0
/**
 *  Display an ad's detail
 *  @param  string  $ad_id  ID of ad to display
 */
function adDetail($ad_id = '')
{
    global $_USER, $_TABLES, $_CONF, $LANG_ADVT, $_CONF_ADVT;
    USES_lib_comments();
    // Determind if this is an administrator
    $admin = SEC_hasRights($_CONF_ADVT['pi_name'] . '.admin');
    $ad_id = COM_sanitizeID($ad_id);
    if ($ad_id == '') {
        // An ad id is required for this function
        return CLASSIFIEDS_errorMsg($LANG_ADVT['missing_id'], 'alert');
    }
    $srchval = isset($_GET['query']) ? trim($_GET['query']) : '';
    // We use this in a few places here, so might as well just
    // figure it out once and save it.
    $perm_sql = COM_getPermSQL('AND', 0, 2, 'ad') . ' ' . COM_getPermSQL('AND', 0, 2, 'cat');
    // get the ad information.
    $sql = "SELECT ad.*\n            FROM {$_TABLES['ad_ads']} ad\n            LEFT JOIN {$_TABLES['ad_category']} cat\n                ON ad.cat_id = cat.cat_id\n            WHERE ad_id='{$ad_id}'";
    if (!$admin) {
        $sql .= $perm_sql;
    }
    $result = DB_query($sql);
    if (!$result || DB_numRows($result) < 1) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['no_ad_found'], 'note', 'Oops...');
    }
    $ad = DB_fetchArray($result, false);
    // Check access to the ad.  If granted, check that access isn't
    // blocked by any category.
    $my_access = CLASSIFIEDS_checkAccess($ad['ad_id'], $ad);
    if ($my_access >= 2) {
        $my_cat_access = CLASSIFIEDS_checkCatAccess($ad['cat_id'], false);
        if ($my_cat_access < $my_access) {
            $my_access = $my_cat_access;
        }
    }
    if ($my_access < 2) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['no_permission'], 'alert', $LANG_ADVT['access_denied']);
    }
    $cat = (int) $ad['cat_id'];
    // Increment the views counter
    $sql = "UPDATE {$_TABLES['ad_ads']} \n            SET views = views + 1 \n            WHERE ad_id='{$ad_id}'";
    DB_query($sql);
    // Get the previous and next ads
    $condition = " AND ad.cat_id={$cat}";
    if (!$admin) {
        $condition .= $perm_sql;
    }
    $sql = "SELECT ad_id\n            FROM {$_TABLES['ad_ads']} ad\n            LEFT JOIN {$_TABLES['ad_category']} cat\n                ON ad.cat_id = cat.cat_id\n            WHERE ad_id < '{$ad_id}' \n            {$condition}\n            ORDER BY ad_id DESC\n            LIMIT 1";
    $r = DB_query($sql);
    list($preAd_id) = DB_fetchArray($r, false);
    $sql = "SELECT ad_id\n            FROM {$_TABLES['ad_ads']} ad\n            LEFT JOIN {$_TABLES['ad_category']} cat\n                ON ad.cat_id = cat.cat_id\n            WHERE ad_id > '{$ad_id}' \n            {$condition}\n            ORDER BY ad_id ASC\n            LIMIT 1";
    $r = DB_query($sql);
    list($nextAd_id) = DB_fetchArray($r, false);
    // Get the user contact info. If none, just show the email link
    $sql = "SELECT * \n            FROM {$_TABLES['ad_uinfo']} \n            WHERE uid='{$ad['uid']}'";
    //echo $sql;
    $result = DB_query($sql);
    $uinfo = array();
    if ($result && DB_numRows($result) > 0) {
        $uinfo = DB_fetchArray($result);
    } else {
        $uinfo['uid'] = '';
        $uinfo['address'] = '';
        $uinfo['city'] = '';
        $uinfo['state'] = '';
        $uinfo['postal'] = '';
        $uinfo['tel'] = '';
        $uinfo['fax'] = '';
    }
    // Get the hot results (most viewed ads)
    $time = time();
    $sql = "SELECT ad.ad_id, ad.cat_id, ad.subject,\n                    cat.cat_id, cat.fgcolor, cat.bgcolor\n        FROM {$_TABLES['ad_ads']} ad\n        LEFT JOIN {$_TABLES['ad_category']} cat\n            ON ad.cat_id = cat.cat_id\n        WHERE ad.exp_date > {$time} \n            {$perm_sql}\n        ORDER BY views DESC \n        LIMIT 4";
    //echo $sql;die;
    $hotresult = DB_query($sql);
    // convert line breaks & others to html
    $patterns = array('/\\n/');
    $replacements = array('<br />');
    $ad['descript'] = PLG_replaceTags(COM_checkHTML($ad['descript']));
    $ad['descript'] = preg_replace($patterns, $replacements, $ad['descript']);
    $ad['subject'] = strip_tags($ad['subject']);
    $ad['price'] = strip_tags($ad['price']);
    $ad['url'] = COM_sanitizeUrl($ad['url']);
    $ad['keywords'] = strip_tags($ad['keywords']);
    // Highlight search terms, if any
    if ($srchval != '') {
        $ad['subject'] = COM_highlightQuery($ad['subject'], $srchval);
        $ad['descript'] = COM_highlightQuery($ad['descript'], $srchval);
    }
    $detail = new Template(CLASSIFIEDS_PI_PATH . '/templates');
    $detail->set_file('detail', 'detail.thtml');
    if ($admin) {
        $base_url = CLASSIFIEDS_ADMIN_URL . '/index.php';
        $del_link = $base_url . '?delete=ad&ad_id=' . $ad_id;
        $edit_link = $base_url . '?edit=ad&ad_id=' . $ad_id;
    } else {
        $base_url = CLASSIFIEDS_URL . '/index.php';
        $del_link = $base_url . '?mode=Delete&id=' . $ad_id;
        $edit_link = $base_url . '?mode=editad&id=' . $ad_id;
    }
    // Set up the "add days" form if this user is the owner
    // or an admin
    if ($my_access == 3) {
        // How many days has the ad run?
        $max_add_days = CLASSIFIEDS_calcMaxAddDays(($ad['exp_date'] - $ad['add_date']) / 86400);
        if ($max_add_days > 0) {
            $detail->set_var('max_add_days', $max_add_days);
        }
    }
    if ($ad['exp_date'] < $time) {
        $detail->set_var('is_expired', 'true');
    }
    USES_classifieds_class_category();
    $detail->set_var(array('base_url' => $base_url, 'edit_link' => $edit_link, 'del_link' => $del_link, 'curr_loc' => adCategory::BreadCrumbs($cat, true), 'subject' => $ad['subject'], 'add_date' => date($_CONF['shortdate'], $ad['add_date']), 'exp_date' => date($_CONF['shortdate'], $ad['exp_date']), 'views_no' => $ad['views'], 'descript' => $ad['descript'], 'ad_type' => CLASSIFIEDS_getAdTypeString($ad['ad_type']), 'uinfo_address' => $uinfo['address'], 'uinfo_city' => $uinfo['city'], 'uinfo_state' => $uinfo['state'], 'uinfo_postcode' => $uinfo['postcode'], 'uinfo_tel' => $uinfo['tel'], 'uinfo_fax' => $uinfo['fax'], 'price' => $ad['price'], 'ad_id' => $ad_id, 'ad_url' => $ad['url'], 'username' => $_CONF_ADVT['disp_fullname'] == 1 ? COM_getDisplayName($ad['uid']) : DB_getItem($_TABLES['users'], 'username', "uid={$ad['uid']}"), 'fgcolor' => $ad['fgcolor'], 'bgcolor' => $ad['bgcolor'], 'cat_id' => $ad['cat_id']));
    // Display a link to email the poster, or other message as needed
    $emailfromuser = DB_getItem($_TABLES['userprefs'], 'emailfromuser', "uid={$ad['uid']}");
    if ($_CONF['emailuserloginrequired'] == 1 && COM_isAnonUser() || $emailfromuser < 1) {
        $detail->set_var('ad_uid', '');
    } else {
        $detail->set_var('ad_uid', $ad['uid']);
    }
    if ($my_access == 3) {
        $detail->set_var('have_userlinks', 'true');
        if ($admin || $_CONF_ADVT['usercanedit'] == 1) {
            $detail->set_var('have_editlink', 'true');
        } else {
            $detail->set_var('have_editlink', '');
        }
    } else {
        $detail->set_var('have_userlinks', '');
    }
    // Retrieve the photos and put into the template
    $sql = "SELECT photo_id, filename\n            FROM {$_TABLES['ad_photo']} \n            WHERE ad_id='{$ad_id}'";
    $photo = DB_query($sql);
    $photo_detail = '';
    $detail->set_var('have_photo', '');
    // assume no photo available
    if ($photo && DB_numRows($photo) >= 1) {
        while ($prow = DB_fetchArray($photo)) {
            $img_small = LGLIB_ImageUrl(CLASSIFIEDS_IMGPATH . '/' . $prow['filename'], $_CONF_ADVT['detail_img_width']);
            $img_disp = CLASSIFIEDS_dispUrl($prow['filename']);
            if (!empty($img_small)) {
                $detail->set_block('detail', 'PhotoBlock', 'PBlock');
                $detail->set_var(array('tn_width' => $_CONF_ADVT['detail_img_width'], 'small_url' => $img_small, 'disp_url' => $img_disp));
                $detail->parse('PBlock', 'PhotoBlock', true);
                $detail->set_var('have_photo', 'true');
            }
        }
    }
    if (DB_count($_TABLES['ad_ads'], 'owner_id', (int) $ad['owner_id']) > 1) {
        $detail->set_var('byposter_url', CLASSIFIEDS_URL . '/index.php?' . "page=byposter&uid={$ad['owner_id']}");
    }
    // Show previous and next ads
    if ($preAd_id != '') {
        $detail->set_var('previous', '<a href="' . CLASSIFIEDS_makeURL('detail', $preAd_id) . "\">&lt;&lt;</a>");
    }
    if ($nextAd_id != '') {
        $detail->set_var('next', '<a href="' . CLASSIFIEDS_makeURL('detail', $nextAd_id) . "\">  &gt;&gt;</a>");
    }
    // Show the "hot results"
    $hot_data = '';
    if ($hotresult) {
        $detail->set_block('detail', 'HotBlock', 'HBlock');
        while ($hotrow = DB_fetchArray($hotresult)) {
            $detail->set_var(array('hot_title' => $hotrow['subject'], 'hot_url' => CLASSIFIEDS_makeURL('detail', $hotrow['ad_id']), 'hot_cat' => displayCat($hotrow['cat_id'])));
            /*$hot_data .= "<tr><td class=\"hottitle\"><a href=\"" .
                            CLASSIFIEDS_makeURL('detail', $hotrow['ad_id']) .
                            "\">{$hotrow['subject']}</a></small></td>\n";
            
                        $hot_data .= "<td class=\"hotcat\">( " . displayCat($hotrow['cat_id']) . 
                                    " )</td></tr>\n";*/
        }
        $detail->parse('HBlock', 'HotBlock', true);
    }
    $detail->set_var('whats_hot_row', $hot_data);
    // Show the user comments
    if (plugin_commentsupport_classifieds() && $ad['comments_enabled'] < 2) {
        $detail->set_var('usercomments', CMT_userComments($ad_id, $ad['subject'], 'classifieds', '', '', 0, 1, false, false, $ad['comments_enabled']));
        //$detail->set_var('usercomments', CMT_userComments($ad_id, $subject,
        //        'classifieds'));
    }
    $detail->parse('output', 'detail');
    $display = $detail->finish($detail->get_var('output'));
    return $display;
}
Ejemplo n.º 3
0
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER, $_SYSTEM;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled || !$this->isAvailable()) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $tpl_dir = PAYPAL_PI_PATH . '/templates/detail/' . $_PP_CONF['product_tpl_ver'];
     $T = new Template($tpl_dir);
     $T->set_file('product', 'product_detail_attrib.thtml');
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $onsale = $this->isOnSale();
     $act_price = $onsale ? $this->sale_price : $this->price;
     $qty_disc_txt = '';
     foreach ($this->qty_discounts as $qty => $pct) {
         $qty_disc_txt .= sprintf('Buy %d, save %.02f%%<br />', $qty, $pct);
     }
     // Get custom text input fields
     if ('' != $this->custom) {
         $T->set_block('product', 'CustAttrib', 'cAttr');
         $text_field_names = explode('|', $this->custom);
         foreach ($text_field_names as $id => $text_field_name) {
             $T->set_var(array('fld_id' => "cust_text_fld_{$id}", 'fld_name' => htmlspecialchars($text_field_name)));
             $T->parse('cAttr', 'CustAttrib', true);
         }
     }
     $T->set_var(array('is_uikit' => $_SYSTEM['framework'] == 'uikit' ? 'true' : '', 'have_attributes' => $this->hasAttributes(), 'id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $onsale ? 'true' : '', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : '', 'qty_disc' => $qty_disc_txt));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20));
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var(array('img_file' => $prow['filename'], 'disp_img' => PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20), 'lg_img' => PAYPAL_URL . '/images/products/' . $prow['filename'], 'img_url' => PAYPAL_URL . '/images/products', 'thumb_url' => PAYPAL_ImageUrl($prow['filename']), 'tn_width' => $_PP_CONF['max_thumb_size'], 'tn_height' => $_PP_CONF['max_thumb_size']));
                 $T->parse('PBlock', 'Thumbnail', true);
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $cbrk = '';
     $T->set_block('product', 'AttrSelect', 'attrSel');
     foreach ($this->options as $id => $Attr) {
         /*if ($Attr['attr_value'] === '') {
               $type = 'text';
           } else {
               $type = 'select';
           }*/
         $type = 'select';
         if ($Attr['attr_name'] != $cbrk) {
             if ($cbrk != '') {
                 // end block if not the first element
                 $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
                 $T->parse('attrSel', 'AttrSelect', true);
             }
             $cbrk = $Attr['attr_name'];
             $attributes = '';
         }
         if ($type == 'select') {
             if ($Attr['attr_price'] != 0) {
                 $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
             } else {
                 $attr_str = '';
             }
             $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
             /*} else {
                   $attributes .= "<input type=\"hidden\" name=\"on{$i}\" 
                           value=\"{$Attr['attr_name']}\">\n";
                   $attributes .= $Attr['attr_name'] . ':</td>
                       <td><input class="uk-contrast uk-form" type"text" name="os' . $i. '" value="" size="32" /></td></tr>';
               */
         }
     }
     if ($cbrk != '') {
         // finish off the last selection
         $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
         $T->parse('attrSel', 'AttrSelect', true);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         if ($name == 'add_cart') {
             // Set the add to cart button in the main form
             $T->set_var('add_cart_button', $html);
         } else {
             $T->set_var('buy_now_button', $html);
             $T->parse('Btn', 'BtnBlock', true);
         }
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }
Ejemplo n.º 4
0
 public function parse($p1, $p2 = '', $fulltag)
 {
     global $_CONF, $_TABLES, $_USER, $LANG01;
     USES_lib_comments();
     $retval = '';
     $skip = 0;
     $dt = new Date('now', $_USER['tzid']);
     // topic = specific topic or 'all'
     // display = how many stories to display, if 0, then all
     // meta = show meta data (i.e.; who when etc)
     // titleLink - make title a hot link
     // featured - 0 = show all, 1 = only featured, 2 = all except featured
     // frontpage - 1 = show only items marked for frontpage - 0 = show all
     // cols - number of columns to show
     // template - the template name
     $topic = $p1;
     if ($topic == 'all') {
         $topic = '';
     }
     $uniqueID = md5($p1 . $p2);
     $display = 10;
     // display 10 articles
     $meta = 0;
     // do not display meta data
     $titleLink = 0;
     // do not use links in title
     $featured = 0;
     // 0 = show all, 1 = only featured, 2 = all except featured
     $frontpage = 0;
     // only show items marked for frontpage
     $cols = 3;
     // number of columns
     $truncate = 0;
     // maximum number of characters to include in story text
     $template = 'headlines.thtml';
     $px = explode(' ', trim($p2));
     if (is_array($px)) {
         foreach ($px as $part) {
             if (substr($part, 0, 8) == 'display:') {
                 $a = explode(':', $part);
                 $display = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 5) == 'meta:') {
                 $a = explode(':', $part);
                 $meta = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 10) == 'titlelink:') {
                 $a = explode(':', $part);
                 $titleLink = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'featured:') {
                 $a = explode(':', $part);
                 $featured = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 10) == 'frontpage:') {
                 $a = explode(':', $part);
                 $frontpage = (int) $a[1];
                 $skip++;
             } elseif (substr($part, 0, 5) == 'cols:') {
                 $a = explode(':', $part);
                 $cols = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'template:') {
                 $a = explode(':', $part);
                 $template = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'truncate:') {
                 $a = explode(':', $part);
                 $truncate = (int) $a[1];
                 $skip++;
             } else {
                 break;
             }
         }
         if ($skip != 0) {
             if (count($px) > $skip) {
                 for ($i = 0; $i < $skip; $i++) {
                     array_shift($px);
                 }
                 $caption = trim(implode(' ', $px));
             } else {
                 $caption = '';
             }
         }
     } else {
         $caption = trim($p2);
     }
     if ($display < 0) {
         $display = 3;
     }
     $hash = CACHE_security_hash();
     $instance_id = 'whatsnew_headlines_' . $uniqueID . '_' . $hash . '_' . $_USER['theme'];
     if (($cache = CACHE_check_instance($instance_id, 0)) !== FALSE) {
         return $cache;
     }
     $archivetid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
     $sql = " (date <= NOW()) AND (draft_flag = 0)";
     if (empty($topic)) {
         $sql .= COM_getLangSQL('tid', 'AND', 's');
     }
     // if a topic was provided only select those stories.
     if (!empty($topic)) {
         $sql .= " AND s.tid = '" . DB_escapeString($topic) . "' ";
     }
     if ($featured == 1) {
         $sql .= " AND s.featured = 1 ";
     } else {
         if ($featured == 2) {
             $sql .= " AND s.featured = 0 ";
         }
     }
     if ($frontpage == 1) {
         $sql .= " AND frontpage = 1 ";
     }
     if ($topic != $archivetid) {
         $sql .= " AND s.tid != '{$archivetid}' ";
     }
     $sql .= COM_getPermSQL('AND', 0, 2, 's');
     $sql .= COM_getTopicSQL('AND', 0, 's') . ' ';
     $userfields = 'u.uid, u.username, u.fullname';
     if ($_CONF['allow_user_photo'] == 1) {
         $userfields .= ', u.photo';
         if ($_CONF['use_gravatar']) {
             $userfields .= ', u.email';
         }
     }
     $orderBy = ' date DESC ';
     $headlinesSQL = "SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND" . $sql . "ORDER BY featured DESC," . $orderBy;
     if ($display > 0) {
         $headlinesSQL .= " LIMIT " . $display;
     }
     $result = DB_query($headlinesSQL);
     $numRows = DB_numRows($result);
     if ($numRows < $cols) {
         $cols = $numRows;
     }
     if ($cols > 6) {
         $cols = 6;
     }
     if ($numRows > 0) {
         $T = new Template($_CONF['path'] . 'system/autotags/');
         $T->set_file('page', $template);
         $T->set_var('columns', $cols);
         $T->set_block('page', 'headlines', 'hl');
         $newstories = array();
         while ($A = DB_fetchArray($result)) {
             $T->unset_var('readmore_url');
             $T->unset_var('lang_readmore');
             if ($A['attribution_author'] != '') {
                 $author = $A['attribution_author'];
             } else {
                 $author = $A['username'];
             }
             $title = COM_undoSpecialChars($A['title']);
             $title = str_replace('&nbsp;', ' ', $title);
             $subtitle = COM_undoSpecialChars($A['subtitle']);
             if ($A['story_image'] != '') {
                 $story_image = $_CONF['site_url'] . $A['story_image'];
             } else {
                 $story_image = '';
             }
             $A['introtext'] = STORY_renderImages($A['sid'], $A['introtext']);
             if (!empty($A['bodytext'])) {
                 $closingP = strrpos($A['introtext'], "</p>");
                 if ($closingP !== FALSE) {
                     $text = substr($A['introtext'], 0, $closingP);
                     $A['introtext'] = $text;
                 }
                 // adds the read more link
                 $T->set_var('readmore_url', COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']));
                 $T->set_var('lang_readmore', $LANG01['continue_reading']);
             }
             if ($truncate > 0) {
                 $A['introtext'] = $this->truncateHTML($A['introtext'], $truncate, '...');
             }
             $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
             $dt->setTimestamp($A['unixdate']);
             if ($A['commentcode'] >= 0) {
                 $cmtLinkArray = CMT_getCommentLinkWithCount('article', $A['sid'], $_CONF['site_url'] . '/article.php?story=' . $A['sid'], $A['comments'], 1);
                 $T->set_var(array('lang_comments' => '', 'comments_count' => $cmtLinkArray['comment_count'], 'comments_url' => $cmtLinkArray['url'], 'comments_url_extra' => $cmtLinkArray['url_extra']));
             } else {
                 $T->unset_var('lang_comments');
                 $T->unset_var('comments_count');
                 $T->unset_var('comments_url');
                 $T->unset_var('comments_url_extra');
             }
             $T->set_var(array('titlelink' => $titleLink ? TRUE : '', 'meta' => $meta ? TRUE : '', 'lang_by' => $LANG01[95], 'lang_posted_in' => $LANG01['posted_in'], 'story_topic_url' => $topicurl, 'title' => $title, 'subtitle' => $subtitle, 'story_image' => $story_image, 'text' => PLG_replaceTags($A['introtext']), 'date' => $A['date'], 'time' => $dt->format('Y-m-d', true) . 'T' . $dt->format('H:i:s', true), 'topic' => $A['topic'], 'tid' => $A['tid'], 'author' => $author, 'author_id' => $A['uid'], 'sid' => $A['sid'], 'short_date' => $dt->format($_CONF['shortdate'], true), 'date_only' => $dt->format($_CONF['dateonly'], true), 'date' => $dt->format($dt->getUserFormat(), true), 'url' => COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']), 'attribution_url' => $A['attribution_url'], 'attribution_name' => $A['attribution_name']));
             $T->parse('hl', 'headlines', true);
         }
         $retval = $T->finish($T->parse('output', 'page'));
         CACHE_create_instance($instance_id, $retval, 0);
     }
     return $retval;
 }
Ejemplo n.º 5
0
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $T = new Template(PAYPAL_PI_PATH . '/templates/detail' . $_PP_CONF['tpl_ver_detail']);
     if ($this->hasAttributes()) {
         $detail_template = 'product_detail_attrib.thtml';
     } else {
         $detail_template = 'product_detail.thtml';
     }
     $T->set_file('product', $detail_template);
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $act_price = $this->sale_price == $this->price ? $this->price : $this->sale_price;
     $T->set_var(array('id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $act_price == $this->price ? '' : 'true', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : ''));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', $prow['filename']);
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var('img_file', $prow['filename']);
                 $T->set_var('img_url', PAYPAL_URL . '/images/products');
                 $T->set_var('thumb_url', PAYPAL_ImageUrl($prow['filename']));
                 $T->parse('PBlock', 'Thumbnail', true);
                 $T->set_var('have_photo', 'true');
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $i = 0;
     $cbrk = '';
     $attributes = '';
     foreach ($this->options as $id => $Attr) {
         if ($Attr['attr_name'] != $cbrk) {
             if ($i > 0) {
                 $attributes .= "</select></td></tr>\n";
             } else {
                 $attributes = '<table border="0">' . "\n";
             }
             $cbrk = $Attr['attr_name'];
             $attributes .= "<tr><td>\n                    <input type=\"hidden\" name=\"on{$i}\" \n                    value=\"{$Attr['attr_name']}\">\n\n                    <input type=\"hidden\" name=\"os{$i}\" \n                    value=\"\">\n\n                    {$Attr['attr_name']}:</td>\n                    <td align=\"left\">\n                    <select name=\"options[]\"\n                    onchange=\"ProcessForm(this.form);\">\n";
             /*<td align=\"left\"><select name=\"pp_os{$i}\"*/
             $i++;
         }
         if ($Attr['attr_price'] != 0) {
             $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
         } else {
             $attr_str = '';
         }
         $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
     }
     if ($attributes != '') {
         $attributes .= "</select></td></tr></table>\n";
         $T->set_var('attributes', $attributes);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         $T->set_var('button', $html);
         $T->parse('Btn', 'BtnBlock', true);
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }