How to open a embed movie from mydabase using PHP - url

This is a clone site I make like www.teensnow.com. That works pretty good, but I don't wont open the target page.And this case is www.xhamster.com. So I wont open a page my and embed the movies in that page! Please take a look on the script ?>
<?php
$coneta = mysql_connect('localhost','root','') or die(mysql_error());
$banco = mysql_select_db('database');
?>
this layer is the target where the thumbs stay
<div align="center" id="box">
<div align="center" id="carrosel" style="width: 90%">
<?php // here is the pagination
$totalthumbsperpage = 64;
$page = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$begin = ($totalthumbsperpage * $page) - $totalthumbsperpage;
$sql = "SELECT * FROM rowname ORDER BY thumb DESC LIMIT $begin, $totalthumbsperpage";
$qr = mysql_query($sql) or die(mysql_error());
while($ln = mysql_fetch_assoc($qr)){
?>
here is where the thumbs is showing on a page. But like you can see, I have the url open in a new page, that's good. But that urls is out of site my site and I want open the movie embedded on a page my.
<a href="<?php echo $ln['url'];?><img src="<?php echo $ln['thumb'];?></a>
<?php
}
?>
</div>
<div align="center">
<?php
$sqlTotal = "SELECT thumb FROM rowname";
$qrTotal = mysql_query($sqlTotal) or die(mysql_error());
$numTotal = mysql_num_rows($qrTotal);
$totalPagina= ceil($numTotal/$totalthumbsperpage);
for($i = 1; $i <= $totalPagina; $i++){
if($i == $pagina)
echo $i";}?>
</div><br><br>
</body>
</html>

Related

How do I start the ouput from the second iteration of a foreach loop?

I have the following code output every iteration of the object. How do I make the output start from the second iteration?
<?php foreach ($data['restos'] as $lid => $resto):?>
<?php
$time_arr = sic_get_start_expire_date_for_user_resto($this->current_user->ID, $lid);
$is_expired_class = '';
if (isset($time_arr['expire_time']) && time()>strtotime( $time_arr['expire_time'] ) ){
$is_expired_class = 'sic-expired-resto';
}
?>
<?php if (!empty($data['restos_metas']['sic_restos_on']) && !empty($level['resto_image_url'])):?>
<div class="resto-outer-wrapper <?php echo $is_expired_class;?>"><img src="<?php echo $resto['resto_image_url'];?>" class="resto" title="<?php echo $resto['label'];?>" /></div>
<?php elseif (!empty($resto['label'])):?>
<div class="sic-above <?php echo $is_expired_class;?>"><?php echo $resto['label'];?></div>
<?php endif;?>
<?php endforeach;?>
The easiest way would be to enclose the output in
if ($uniqueVar) {
// OUTPUT
} else {
$uniquVar = true;
}
Which for your code would look like:
<?php foreach ($data['restos'] as $lid => $resto):?>
<?php
$time_arr = sic_get_start_expire_date_for_user_resto($this->current_user->ID, $lid);
$is_expired_class = '';
if (isset($time_arr['expire_time']) && time()>strtotime( $time_arr['expire_time'] ) ){
$is_expired_class = 'sic-expired-resto';
}
?>
//----------------------------------
<?php if ($notFirstIteration):?>
//----------------------------------
<?php if (!empty($data['restos_metas']['sic_restos_on']) && !empty($level['resto_image_url'])):?>
<div class="resto-outer-wrapper <?php echo $is_expired_class;?>">
<img src="<?php echo $resto['resto_image_url'];?>" class="resto" title="<?php echo $resto['label'];?>" />
</div>
<?php elseif (!empty($resto['label'])):?>
<div class="sic-above <?php echo $is_expired_class;?>"><?php echo $resto['label'];?>
</div>
<?php endif;?>
//--------------------------------
<?php else:?>
<?php $notFirstIteration = true;?>
<?php endif;?>
//--------------------------------
<?php endforeach;?>
This will be true for the second iteration and onward.

Display posts on Wordpress for custom post type query

I am having a few issues with displaying more than 10 posts of a particular post type. The code I have currently is:
<?php get_header();
$ppp = ( !is_paged() ) ? '10' : '15';
$ofs = ( get_query_var('paged') != 0 ) ? ( ( get_query_var('paged') - 1 ) * 15 ) - 5 : 0;
// WP_Query arguments
$args = array (
'post_type' => array( 'book' ),
'pagination' => true,
'paged' => get_query_var('paged'),
'posts_per_page' => $ppp,
'offset' => $ofs,
'ignore_sticky_posts' => false,
);
// The Query
$query = new WP_Query( $args ); ?>
<section class="books <?php if(get_query_var('paged') == 0){ echo 'first-page'; } else { echo 'next-page'; } ?>">
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php $fImg = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ); $fi = $fImg[0]; ?>
<a href="<?php the_permalink(); ?>" class="grid-item-story" style="background-image: url('<?php echo $fi; ?>');">
<article <?php post_class(); ?> id="book-<?php the_ID(); ?>">
<div class="book-item-wrap">
<div class="book-item-inner">
<div class="book-item-content">
<div class="book-item-content-inner">
<p class="published-date"><?php the_time('M j, Y'); ?></p>
<?php if ($query->current_post == 0 && !is_paged() ) { ?>
<h1><?php the_title(); ?></h1>
<?php } else { ?>
<h1><?php echo getBookTitle(get_the_title()); ?></h1>
<?php } ?>
<div><span class="button">Read</span></div>
</div>
</div>
</div>
</div>
</article>
</a>
<?php endwhile; endif; ?>
<div class="clear"></div>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
</section>
<?php get_footer(); ?>
This is the full code of my front-page.php file. On my first page, there will be 10 posts. On every subsequent page, there will be 15. This is because my posts are displayed in five rows of three posts per row, except on the first page where the first post is two "posts" wide and three "posts" tall. There are 50 posts in total for this post type.
Because of this, there should be only four pages:
Posts 1 - 10
Posts 11 - 25
Posts 26 - 40
Posts 41 - 50
However, the next / previous links are appearing on page 4, meaning there is a link to a page 5 which does not have any content. In addition, the offset doesn't seem to work, meaning page 4 displays five posts and not ten. (Fixed by changing !is_paged() to get_query_var('paged') != 0) I've added a formula to calculate the offset to see if that would fix it, which it doesn't, even though it does give the correct position when I echo it elsewhere. I have tried the workaround listed on the WP_Query page in the Codex (correcting for the found_posts issue), but nothing seems to remove that fifth page. Even if I manually set the number of posts to 15 for every page, there is still a fifth page. I've tried WP_Query and get_posts(), and neither work. Is there something I have missed?
Thanks to Pieter's comment, I have been able to find a fix. According to the codex page, I can set the maximum number of pages to display. It just became a simple matter of manually setting that number.
In the <?php ?> tag for my next_posts_link function, just before I called the function, I added these two lines of code:
// Get the total number of posts found
$pc = $query->found_posts;
// Check if $pc is less than 11.
// If so, delete 10 from $pc (for the posts on the first page), then divide it by 15 (for the posts on other pages).
// Add 1 to account for the first page.
// Otherwise, return 1, because there will only be one page.
$mnp = ( $pc < 11 ) ? 1 : ceil( ( $pc - 10 ) / 15 ) + 1;
Comments have been added for your benefit; they aren't included in my file. Although I probably should add them. Testing it by adding one too many posts to cleanly fit on a page has shown it works. It probably doesn't look pretty, but it works, so I'm not complaining.

getting the multilingual alias. - drupal_get_path_alias

I am trying to create a multilingual site the following code outputs my main menu, however the links are retained as english when the user switches languages. I am using i8ln and entity translate. The two nodes exist so how do I retrieve the link for the multilingual page? I thought drupal_get_path_alias() would work by switching in the language. Code below.
<ul id="main-menu">
<?php
foreach($main_menu as $index)
{
dsm($index);
$path = file_create_url($index['menu_icon']['path']);
$class = $index['attributes']['class'][0];
$current = "node/".$node->nid;
$lang_name = $language->language ;
$linky = drupal_get_path_alias($index['href'], $lang_name);
if ($current == $index['href']) {
$class .= " selected";
};
print '<li class="'.$class.'">
<img src="'.$path.'" alt="icon-rockfall" />
<a class="'.$class.' textlink" href="/'.$linky.'">'.$index['title'].'</a></li>';
}
?>
</ul>
</nav>
<?php endif; ?>
I had the same problem, I resolved it with the code below:
<?php
global $language;
$url = url('node/1', array('language' => $language));
?>
Use the global $language object available.
This works for me:
<?php
global $language;
$url_nodo = url('node/' . $id_nodo, array('language' => $language));
$url_path = drupal_get_path_alias($url_nodo);
?>

Issues with sfDoctrinePager pagination

I am using sfDoctrinePager in my module. I search the table on one or more criteria. First time the result displayed is correct but after it if I click on page 2 or more it again gives me the whole resultset and my search resultset is lost.
I am facing this issue for the first time, even though I have been using sfDoctrinePager since a long time.
I get this Array from my search form
(
[field_type] => log_type
[field_value] => ABC
[is_active] => on
)
I send this array variable to my model:
$getQuery = $objMgr->getSearchQuery($request->getPostParameters());
** The query which runs in model is:
public function getSearchQuery($arrSearchValues)
{
$q = Doctrine_Query::create()
->select('u.*')
->from('SomsConfigValues u');
->where('u.deleted_at IS NULL');
if(isset($arrSearchValues['is_active']) && $arrSearchValues['is_active'] == 'on'){
$q->where('u.is_active = ?', 1);
}
if(isset($arrSearchValues['field_type']) && $arrSearchValues['field_type'] != ""){
$revertChg = ucwords(str_replace("_", " ", $arrSearchValues['field_type']));
$q->andWhere('u.field_type = ?', $revertChg);
}
if(isset($arrSearchValues['field_value']) && $arrSearchValues['field_value'] != ''){
$q->andWhere('u.field_type = ?', $arrSearchValues['field_value']);
}
return $q;
}
First time I get the perfect searched result, but second time (when I click on page 2 it gives me whole resultset).
My action is:
public function executeIndex(sfWebRequest $request)
{
$objMgr = AdminFactory::adminObject();
$getQuerys = $objMgr->getSearchQuery($request->getPostParameters());
$this->config_values = $getQuerys;
$this->pager = new sfDoctrinePager('configValues', sfConfig::get('app_max_row_display'));
$this->pager->setQuery($this->config_values);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
}
The template where I am using this pagination is:
<div class="grid_footer">
<div style="padding:5px;">
<?php if(count($pager->getLinks())) : ?>
<div class="tableControl">
<div class="pagination_inner">
<?php if(!$pager->isFirstPage()){ ?>
<?php echo link_to1(image_tag('/images/first.png'), 'configValues/index?page='.$pager->getFirstPage()) ?>
<?php echo link_to1(image_tag('/images/previous.png'), 'configValues/index?page='.$pager->getPreviousPage()) ?>
<?php } ?>
<div class="numbers">
<?php if ($pager->haveToPaginate()): ?>
<?php $links = $pager->getLinks(); foreach ($links as $page): ?>
<?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'configValues/index?page='.$page) ?>
<?php endforeach ?>
<?php endif ?>
</div>
<?php if(!$pager->isLastPage()){ ?>
<?php echo link_to1(image_tag('/images/next.png'), 'configValues/index?page='.$pager->getNextPage()) ?>
<?php echo link_to1(image_tag('/images/last.png'), 'configValues/index?page='.$pager->getLastPage()) ?>
<?php } ?>
</div>
</div>
<?php echo $pager->getNbResults() ?> results (page <?php echo $pager->getPage(); ?>/<?php echo count($pager->getLinks()); ?>)
<?php endif; ?>
</div>
</div>
I was having exactly the same problem. The only way around this I found is as you said, to store the query. Instead of using the session, create an attribute in the user to store this.
in the action class put something like...
$this->getUser()->setAttribute('searchQuery', $getQuery);
This value persists through the session, so you can retreive it using e.g.
$storedQuery = $this->getUser()->getAttribute('searchQuery');
You can view the User attributes via the config item on the dev toolbar.

How to get downloadable product links after successfull order

After a successfull order I would like to propose directly the downloadable URL for products buyer bought in the success.phtml file.
I wrote this piece of code to know product's values of the latest order:
// Get the latest Order ID
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
// Get every products on the latest order
$items = $order->getAllItems();
// Loop the products
foreach ($items as $item){
$product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());
// HERE I NEED FUNCTION TO GET DOWNLOADABLE URL LINK
}
I found a solution, here it is:
First, create a new .phtml file in template/downloadable/ , I called mine downloadablelist.phtml
Then copy all of template/downloadable/customer/products/list.phtml in our new downloadablelist.phtml
This will give us a copy of the customer account my downloadable products list.
Call our block in success page :
<?php echo $this->getLayout()->createBlock('downloadable/customer_products_list')->setTemplate('downloadable/checkout/downloadablelist.phtml')->toHtml(); ?>
Now I cleaned up what I don't need from the product list. I removed the table and added a ul instead.
Next is to show only the products that are made from the last order.
<?php
$_items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(count($_items)):
$_group_id = Mage::helper('customer')->getCustomer()->getGroupId();
echo '<p><strong>'.$this->__('Downloadable products').' : </strong></p>'; ?>
<ul style="margin-left: 30px; list-style: disc;">
<?php foreach ($_items as $_item):
$itemOrderId = $_item->getPurchased()->getOrderIncrementId();
if($itemOrderId == $orderId) {?>
<li><?php echo $this->htmlEscape($_item->getPurchased()->getProductName()) ?> - <a href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>" title="<?php echo Mage::helper('downloadable')->__('Start Download') ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $_item->getLinkTitle() ?></a></li>
<?php }
endforeach; ?>
</ul>
<?php endif; ?>
I changed the url the original downloadable file had to :
href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>"
Thank you
This worked for me:
$links = Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $item->getId());
foreach ($links as $link) {
echo Mage::helper('downloadable')->__('download') .
$this->getUrl('downloadable/download/link',
array('id' => $link->getLinkHash(), '_store' => $order()->getStore(),
'_secure' => true, '_nosid' => true));
}

Resources