';
if( isset($this->addonReviews[$id]) ){
echo 'You posted the following review on '.\gp\tool::date($langmessage['strftime_date'],$this->addonReviews[$id]['time']);
}
echo '';
return true;
}
/**
* Get Addon info for rating
* Return true if it can be rated
*
*/
public function CanRate(){
$this->GetAddonData();
$arg =& $_REQUEST['arg'];
switch($this->config_index){
case 'themes':
$this->GetAddonRateInfoTheme($arg);
break;
case 'addons':
$this->GetAddonRateInfoPlugin($arg);
break;
default:
return false;
}
if( !\gp\tool::IniGet('allow_url_fopen') ){
$this->messages[] = 'Your installation of PHP does not support url fopen wrappers.';
}
if( count($this->messages) > 0 ){
$message = 'Oops, you are currently unable to rate this addon for the following reasons:';
$message .= '
';
$message .= '
'.implode('
',$this->messages).'
';
$message .= '
';
message($message);
$this->ShowRatingText = false;
return false;
}
return true;
}
public function GetAddonRateInfoTheme($dir){
global $dataDir, $langmessage;
$dir = str_replace('\\','/',$dir);
$dir = str_replace('../','./',$dir);
$full_dir = $dataDir.$dir;
if( !file_exists($full_dir) ){
$this->messages[] = $langmessage['OOPS'].' (directory doesn\'t exist)';
return false;
}
$ini = $this->GetAvailInstall($full_dir);
if( $ini === false ){
$this->messages[] = 'This add-on does not have an ID assigned to it. The developer must update the install configuration.';
return false;
}
if( !isset($ini['Addon_Unique_ID']) ){
$this->messages[] = 'This add-on does not have an ID assigned to it. The developer must update the install configuration.';
return false;
}
$this->pass_arg = $dir;
$this->addon_info['id'] = $ini['Addon_Unique_ID'];
$this->addon_info['name'] = $ini['Addon_Name'];
return true;
}
public function GetAddonRateInfoPlugin($arg){
global $config;
if( isset($config['addons'][$arg]) && isset($config['addons'][$arg]['id']) ){
$this->pass_arg = $config['addons'][$arg]['id'];;
$this->addon_info['id'] = $config['addons'][$arg]['id'];
$this->addon_info['name'] = $config['addons'][$arg]['name'];
return true;
}
if( !is_numeric($arg) ){
$this->messages[] = 'This add-on does not have an ID assigned to it. The developer must update the install configuration.';
return false;
}
foreach($config['addons'] as $addonDir => $data){
if( isset($data['id']) && ($data['id'] == $arg) ){
$this->pass_arg = $arg;
$this->addon_info['id'] = $data['id'];
$this->addon_info['name'] = $data['name'];
return true;
}
}
foreach($this->addonHistory as $data ){
if( isset($data['id']) && ($data['id'] == $arg) ){
$this->pass_arg = $arg;
$this->addon_info['id'] = $data['id'];
$this->addon_info['name'] = $data['name'];
return true;
}
}
$this->messages[] = 'The supplied add-on ID is not in your add-on history.';
return false;
}
/**
* Send the addon rating to server
*
*/
public function SendAddonReview(){
global $langmessage, $config, $dirPrefix;
$this->page->ajaxReplace = array();
$data = array();
if( !$this->CanRate() ){
return;
}
if( !is_numeric($_POST['rating']) || ($_POST['rating'] < 1) || ($_POST['rating'] > 5 ) ){
message($langmessage['OOPS'].' (Invalid Rating)');
return false;
}
$id = $this->addon_info['id'];
//don't send if it hasn't chagned
if( isset($this->addonReviews[$id]) ){
$data['review_id'] = $this->addonReviews[$id]['review_id'];
//if it hasn't changed..
if( ($_POST['rating'] == $this->addonReviews[$id]['rating'])
&& ($_POST['review'] == $this->addonReviews[$id]['review']) ){
$this->ShowRatingText = false;
message('Your review has been saved and will be posted pending approval.');
return true;
}
}
//send rating
$data['addon_id'] = $id;
$data['rating'] = (int)$_POST['rating'];
$data['review'] = $_POST['review'];
$data['cmd'] = 'rate';
$data['HTTP_HOST'] = \gp\tool::ServerName();
$data['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'];
$data['dirPrefix'] = $dirPrefix;
if( isset($_POST['show_site']) && $_POST['show_site'] == 'hidden' ){
$data['show_site'] = 'hidden';
}
$review_id = $this->PingRating($data);
if( $review_id === false ){
return false;
}
//save review information
$this->addonReviews[$id] = array();
$this->addonReviews[$id]['rating'] = (int)$_POST['rating'];
$this->addonReviews[$id]['review'] = substr($_POST['review'],0,500);
$this->addonReviews[$id]['review_id'] = $review_id;
$this->addonReviews[$id]['time'] = time();
$this->SaveAddonData();
$this->ShowRatingText = false;
message('Your review has been saved and will be posted pending approval.');
return true;
}
public function PingRating($data){
$path = CMS_DOMAIN.'/index.php/Special_Addons?'.http_build_query($data,'','&');
$contents = \gp\tool\RemoteGet::Get_Successful($path);
return $this->RatingResponse($contents);
}
public function RatingResponse($contents){
global $langmessage;
if( empty($contents) ){
message($langmessage['OOPS'].' (empty rating)');
return false;
}
//!! these responses should be more detailed
list($response,$detail) = explode(':',$contents);
$response = trim($response);
$detail = trim($detail);
if( $response == 'successful_rating_request' ){
return $detail;
}
//invalid_rating_request
switch($detail){
case 'no_addon';
message('The supplied addon id was invalid.');
break;
default:
message($langmessage['OOPS'].' (Detail:'.htmlspecialchars($detail).')');
//message($contents);
break;
}
return false;
}
/**
* Get a list of installed addons
*
*/
public function GetInstalledComponents($from,$addon){
$result = array();
if( !is_array($from) ){
return $result;
}
foreach($from as $name => $info){
if( !isset($info['addon']) ){
continue;
}
if( $info['addon'] !== $addon ){
continue;
}
$result[] = $name;
}
return $result;
}
//remove gadgets from $gpLayouts
public function RemoveFromHandlers($gadgets){
global $gpLayouts;
if( !is_array($gpLayouts) || !is_array($gadgets) ){
return;
}
foreach($gpLayouts as $theme => $containers){
if( !is_array($containers) || !isset($containers['handlers']) || !is_array($containers['handlers']) ){
continue;
}
foreach($containers['handlers'] as $container => $handlers){
if( !is_array($handlers) ){
continue;
}
foreach($handlers as $index => $handle){
$pos = strpos($handle,':');
if( $pos > 0 ){
$handle = substr($handle,0,$pos);
}
foreach($gadgets as $gadget){
if( $handle === $gadget ){
$handlers[$index] = false; //set to false
}
}
}
$handlers = array_diff($handlers, array(false)); //remove false entries
$handlers = array_values($handlers); //reset keys
$gpLayouts[$theme]['handlers'][$container] = $handlers;
}
}
}
public function CleanHooks($addon,$keep_hooks = array()){
global $config, $gp_hooks;
if( !isset($config['hooks']) ){
return;
}
foreach($config['hooks'] as $hook_name => $hook_array){
foreach($hook_array as $hook_dir => $hook_args){
//not cleaning other addons
if( $hook_dir != $addon ){
continue;
}
if( !isset($keep_hooks[$hook_name]) ){
unset($config['hooks'][$hook_name][$hook_dir]);
unset($gp_hooks[$hook_name][$hook_dir]);
//message('remove this hook: '.$hook_name);
}
}
}
//reduce further if empty
foreach($config['hooks'] as $hook_name => $hook_array){
if( empty($hook_array) ){
unset($config['hooks'][$hook_name]);
unset($gp_hooks[$hook_name]);
}
}
}
/**
* Determine if the addon (identified by $ini_info and $source_folder) is an upgrade to an existing addon
*
* @return mixed
*/
public function UpgradePath($ini_info,$config_key='addons'){
global $config, $dataDir;
if( !isset($config[$config_key]) ){
return false;
}
//by id
if( isset($ini_info['Addon_Unique_ID']) ){
foreach($config[$config_key] as $addon_key => $data){
if( !isset($data['id']) || !is_numeric($data['id']) ){
continue;
}
if( (int)$data['id'] == (int)$ini_info['Addon_Unique_ID'] ){
return $addon_key;
}
}
}
//by name
if( isset($ini_info['Addon_Name']) ){
foreach($config[$config_key] as $addon_key => $data){
if( isset($data['name']) && $data['name'] == $ini_info['Addon_Name'] ){
return $addon_key;
}
}
}
//by path
if( isset($ini_info['source_folder']) ){
foreach($config[$config_key] as $addon_key => $data){
if( !isset($data['code_folder_part']) ){
continue;
}
$source_folder = $dataDir.$data['code_folder_part'];
if( $source_folder === $ini_info['source_folder'] ){
return $addon_key;
}
}
}
return false;
}
public function AddonPanelGroup($addon_key, $show_hooks = true, $format = false ){
$this->AddonPanel_Special($addon_key,$format);
$this->AddonPanel_Admin($addon_key,$format);
$this->AddonPanel_Gadget($addon_key,$format);
if( $show_hooks ){
$this->AddonPanel_Hooks($addon_key,$format);
}
}
public function AdminLinkList($links, $label, $format){
$_links = array();
foreach($links as $linkName => $linkInfo){
$_links[] = \gp\tool::Link($linkName,$linkInfo['label']);
}
$this->FormatList($_links,$label,$format);
}
public function FormatList($links, $label, $format = false){
if( empty($links) ){
return;
}
if( !$format ){
$format = array();
$format['start'] = '