I am frankly not into coding but need help in modifying an existing code.
As you can see in below code, the script tries to call the URL -> store or destination whichever it maybe.
I simply want to prefix a static URl before the below URL is generated.
For example - if through below code I get : www.amazon.com, I'm simply trying to find a way where instead of direct link showing up -> it should be something like:
www.domain.com/script.php?id=www.amazon.com
I think we need to modify the code somewhere here. Hence basically -> "www.domain.com/script.php?id=" should be prefixed in ALL outgoing URLs.
Any help is really appreciated!
(hope i dont get banned >_<)
/**
* Get destination url
*
* #since 1.0.0
* #param bool $store_url_if_empty
* #return bool|string
*/
public function get_destination_url( $store_url_if_empty = true ) {
$url = '';
if ( ! $this->_wpc_destination_url && $store_url_if_empty ) {
$url = $this->get_store_site_url();
} else {
$url = $this->_wpc_destination_url;
}
if ( ! $url ) {
$url = $this->store->get_url();
}
return $url;
}
Just before return statement
$static = "www.domain.com/script.php?id=";
$url =$static.$url;
return $url;
Related
I want to put my module in Prestashop market place, and make it standard everyone can use it. This plugin needs to know the admin directory name dynamically to do its service.
I have searched on the Internet a lot of times, but I didn't find a solution to this issue.
You can use _PS_ADMIN_DIR_ witch is set in [your_admin_dir]/index.php:
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', getcwd());
}
This constant is only set when you're on an admin context. Your FrontOffice doesn't have knowledge of this directory and should not for obvious security reason.
There's also a getAdminLink method in class Link:
/**
* Use controller name to create a link
*
* #param string $controller
* #param bool $with_token include or not the token in the url
* #return string url
*/
public function getAdminLink($controller, $with_token = true)
{
$id_lang = Context::getContext()->language->id;
$params = $with_token ? array('token' => Tools::getAdminTokenLite($controller)) : array();
return Dispatcher::getInstance()->createUrl($controller, $id_lang, $params, false);
}
Example:
// Here we create a link to the dashboard without token
$this->context->link->getAdminLink(Tab::getClassNameById(1), false)
I'm scraping data from an API. The problem is that I'm querying the data too often for each pageload, so I'd like to store the data on the server after the first query. This should be fine according to the TOS.
On example.com/page:
<?php include 'example.com/data'; ?>
On example.com/data:
<?php include 'api.com/include'; ?>
So I am including a page from my server, and that page is including the api data from the external server.
Question 1: How can I tell example.com/data to WRITE or save the information from api.com/include as a file on the server such as example.com/data1.php ?
Question 2: How can I tell example.com/page to php include example.com/data1.php, and if it's a 404 (doesn't exist) to include example.com/data instead?
With both questions 1 and 2 answered I can query the api once, store the data as a file, and if that file exists use the data from that page rather than have to query the api each time the page is loaded.
If you know of a better way of doing this I'd be grateful to learn it. Though it is important that I include from example.com/data from example.com/page rather than directly from api.com/include because example.com/data has the correct code handlers to properly interpret and filter the information from api/include.
If you can answer either of the two questions it would be a great starting ground for me solving the other problem.
Thank you!
You should use a class to decouple this behaviour. Something like this:
<?php
class ReadApiFromDomainDotCom
{
const TTL = 3600; // File is fresh for 3600 sec
const FILE_NAME = 'whatever.txt';
const API_ADDRESS = "http://api.whatever.com";
/**
* #return string
*/
public function get()
{
if ($this->isCacheValid()) {
return file_get_contents(self::FILE_NAME);
}
return $this->readApi();
}
/**
* #return bool
*/
private function isCacheValid()
{
if (!file_exists(self::FILE_NAME)) {
return false;
}
if ($this->isExpired()) {
return false;
}
return true;
}
/**
* #return bool
*/
private function isExpired()
{
return time() - filemtime(self::FILE_NAME) > self::TTL;
}
/**
* #return string
*/
private function readApi()
{
$data = file_get_contents(self::API_ADDRESS);
file_put_contents(self::FILE_NAME, $data);
return $data;
}
}
Then it will be easy as:
$apiReader = new ReadApiFromDomainDotCom();
$data $apiReader->get();
Haven't tested this code so you will have to fiddle with it a bit. Add namespace, paths and so on.
I'm trying to remove cached images (which are created with LiipImagineBundle) when the source image is deleted or updated. I have already found out that it could be done using CacheManager ( https://github.com/liip/LiipImagineBundle/issues/132 )
The problem is that I can't figure it out how to use it exactly. What else do I need to add (like libraries) to my code despite these three lines:
$cacheManager = $this->get('liip_imagine.cache.manager');
$cacheManager->resolve($this->getRequest(),$pngPath,$filter);
$cacheManager->remove($pngPath, $filter);
I believe there should be something like
$cacheManager = new CacheManager();
I would really appreciate if anyone could explain me how to do that in more detail.
So, for example in your controller:
/**
* Remove an image in the cache based on its relative path and the filter applied to it
*
* #param string $path
* #param string $filter
*
* #return void
*/
protected function removeCachedImageAction($path, $filter)
{
$cacheManager = $this->container->get('liip_imagine.cache.manager');
// Remove the cached image corresponding to that path & filter, if it is stored
if ($cacheManager->isStored($path, $filter)) {
$cacheManager->remove($path, $filter);
}
}
/**
* An action that doesn't do much except testing the function above
*
* #param Request $request
*
* #return void
*/
protected function whateverAction(Request $request)
{
$path = //... probably from the request
$filter = //... probably from the request
// Remove the cached image
$this->removeCachedImage($path, $filter);
// ...
}
As you can see in the CacheManager, the function that you'd like to use is:
public function remove($paths = null, $filters = null){ ... }
If $paths is null, the function assumes that you want to remove the cached images for ALL PATHS that have been resolved with the $filters provided.
If $filters is null, the function assumes that you want to remove the cached images corresponding for the $paths provided and that have previously been resolved with ALL FILTERS.
If $paths and $filters are null, the function assumes that you want to remove the cached images corresponding to ALL PATHS and for ALL FILTERS. Basically ALL CACHED IMAGES.
Warning: Parameter 3 to showBlogSection() expected to be a reference, value given in /home/smartsta/public_html/includes/Cache/Lite/Function.php on line 100
I'm getting the above error displaying within my content areas on my Joomla site all a sudden, any suggestions?
Update: No such luck finding access to defined file and directory within godaddy ftp file directory, ftp, or Joomal C-panel.
Within FTP, I cannot find access to this particular file to investigate what is on line 100.
Within the Joomla panel, in Global Configurations, I was able to toggle 'error message' to none for atleast this error to be hidden. Within the cache directory I do not see any options to get into the folder, though it displays.
I also see this at the bottom of that c-panel screen, but just links to a joomla help site, and within the fields I do not see described area to toggle 'ON or OFF'
"Following PHP Server Settings are not optimal for Security and it is recommended to change them:
PHP register_globals setting is ON instead of OFF
"
Update2!:
I've found the file in question, below is the code. Line 100 only states:
global $$object_123456789;
application/x-httpd-php Function.php
PHP script text
<?php
/**
* This class extends Cache_Lite and can be used to cache the result and output of functions/methods
*
* This class is completly inspired from Sebastian Bergmann's
* PEAR/Cache_Function class. This is only an adaptation to
* Cache_Lite
*
* There are some examples in the 'docs/examples' file
* Technical choices are described in the 'docs/technical' file
*
* #package Cache_Lite
* #version $Id: Function.php 47 2005-09-15 02:55:27Z rhuk $
* #author Sebastian BERGMANN <sb#sebastian-bergmann.de>
* #author Fabien MARTY <fab#php.net>
*/
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
require_once( $mosConfig_absolute_path . '/includes/Cache/Lite.php' );
class Cache_Lite_Function extends Cache_Lite
{
// --- Private properties ---
/**
* Default cache group for function caching
*
* #var string $_defaultGroup
*/
var $_defaultGroup = 'Cache_Lite_Function';
// --- Public methods ----
/**
* Constructor
*
* $options is an assoc. To have a look at availables options,
* see the constructor of the Cache_Lite class in 'Cache_Lite.php'
*
* Comparing to Cache_Lite constructor, there is another option :
* $options = array(
* (...) see Cache_Lite constructor
* 'defaultGroup' => default cache group for function caching (string)
* );
*
* #param array $options options
* #access public
*/
function Cache_Lite_Function($options = array(NULL))
{
if (isset($options['defaultGroup'])) {
$this->_defaultGroup = $options['defaultGroup'];
}
$this->Cache_Lite($options);
}
/**
* Calls a cacheable function or method (or not if there is already a cache for it)
*
* Arguments of this method are read with func_get_args. So it doesn't appear
* in the function definition. Synopsis :
* call('functionName', $arg1, $arg2, ...)
* (arg1, arg2... are arguments of 'functionName')
*
* #return mixed result of the function/method
* #access public
*/
function call()
{
$arguments = func_get_args();
$id = serialize($arguments); // Generate a cache id
if (!$this->_fileNameProtection) {
$id = md5($id);
// if fileNameProtection is set to false, then the id has to be hashed
// because it's a very bad file name in most cases
}
$data = $this->get($id, $this->_defaultGroup);
if ($data !== false) {
$array = unserialize($data);
$output = $array['output'];
$result = $array['result'];
} else {
ob_start();
ob_implicit_flush(false);
$target = array_shift($arguments);
if (strstr($target, '::')) { // classname::staticMethod
list($class, $method) = explode('::', $target);
$result = call_user_func_array(array($class, $method), $arguments);
} else if (strstr($target, '->')) { // object->method
// use a stupid name ($objet_123456789 because) of problems when the object
// name is the same as this var name
list($object_123456789, $method) = explode('->', $target);
global $$object_123456789;
$result = call_user_func_array(array($$object_123456789, $method), $arguments);
} else { // function
$result = call_user_func_array($target, $arguments);
}
$output = ob_get_contents();
ob_end_clean();
$array['output'] = $output;
$array['result'] = $result;
$this->save(serialize($array), $id, $this->_defaultGroup);
}
echo($output);
return $result;
}
}
?>
It is not exactly an error. It is a warning.
Suddenly? Perhaps you have upgraded/updated your PHP version. Or changed PHP configuration to "strict mode".
The message "expected to be a reference, value given" means the called function expected to receive a reference, not a value. Look:
$something = 9;
show_section($something);
// here you are passing a variable
// this will be accepted as a reference
show_section(9);
// here you are NOT passing a reference
// here you are passing a VALUE
When you pass "by reference", the function can change the variable value... in the example above:
function show_section(&$parameter) {
$parameter = 'changed!';
}
Note the ampersand symbol & before the $parameter - this is how we specify a function requires a REFERENCE.
AFTER the function call, in the example above, the variable $something value will be the changed! string.
The line throwing the error is NOT the "global" one. It is the next:
$result = call_user_func_array(array($$object_123456789, $method), $arguments);
The problem here is that the function is being called indirectly by using the "call_user_func_array" function.
A solution would be transforming all arguments into references. Suggestion:
foreach ($arguments as $count => $value)
{
$param = 'param' . $count;
$$param = $value;
$arguments[$count] = &$$param;
}
Put the code above in the beginning of the call function, right after the following line:
$id = serialize($arguments);
Give this a try!
I've got this code, but I'm not sure I make it work:
/**
* Function: youtube data grabber
*
* #description :
* #param $ : video code, url type (embed/url)
* #return : data array
* #author : Mamun.
* #last -modified-by: Mamun.
*/
if (! function_exists('youtube_data_grabber'))
{
function youtube_data_grabber($video_code, $link_type = "embed")
{
if ($video_code != '')
{
if ($link_type == "embed")
{
$splited_data = explode("=",$video_code);
$video_unique_code = substr(strrchr($splited_data[4],"/"),1,-strlen(strrchr($splited_data[4],"&")));
}
else if ($link_type == "url")
{
$splited_data = explode("=",$video_code);
$video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],"&")));
}
else
{
return;
}
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$video_unique_code;
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
return $sxml;
}
}
} // End Youtube Function
I'm not sure how to activate it is what I'm trying to say. I placed it in the controller and it's within a function for one of my pages. I don't have any syntax errors. I just don't know how to wake it up and make it work. I thought I could just put youtube_data_grabber('http://www.youtube.com/watch?v=LAcrFym10ZI', 'url'); but that didn't work.
I got the code from this blog, and I have the zend functionality working. I tested it earlier and had no errors. I'm just having trouble with this youtube part.
Any ideas?
That code should go in a helper or plugin not in the controller. The first part of the code on that page should be in your controller. The one you pasted is just an alternate version.
Save your code to application/helpers/youtube_helper.php, then in your controller go ahead and call $this->load->helper('youtube').
Only then will your youtube_data_grabber() function be available.