A few different ways to get a Product’s Image in Magento
$_product->getImageUrl()
$this->helper('catalog/image')->init($_product, 'image')
$this->helper('catalog/image')->init($_product, 'small_image')
$this->helper('catalog/image')->init($_product, 'small_image')->resize(100,100)
I’m going to use the Tasks Module as an example. I will link the ‘Contact’ field to the contacts module detail view.
Open /modules/Tasks/Dashlets/MyTasksDashlet/MyTasksDashlet.data.php
Initially it looks like this:
'contact_name' => array( 'width' => '8', 'label' => 'LBL_LIST_CONTACT' ),
To make this field link to the contacts module:
'contact_name' => array(
'width' => '8',
'label' => 'LBL_LIST_CONTACT',
'link' => true,
'action' => 'DetailView',
'module' => 'Contacts',
'id' => 'CONTACT_ID',
'related_fields' => array('contact_id')
),
The main fields are:
link: True/False
module: The name of the destination module
action: DetailView or EditView
id: The field that contains the ID for the related field. If it doesn’t work lower case, try it in uppercase
related_fields: The field that contains the relation ID – This should be the same as ‘id’
You can hide a SubPanel in an upgrade safe way but unsetting the subpanel via PHP.
Example:
You can hid the Leads SubPanel into Accounts module by customizing the custom/modules/Accounts/Ext/Layoutdefs/layoutdefs.ext.php, which is a upgrade safe customization. Add the following to the end of the file, before the closing PHP tag.
unset($layout_defs['Accounts']['subpanel_setup']['leads']);
After searching for a while, I finally found out how to manually delete or remove a sugar crm relationship that was created in studio. I tested this on Sugar 5.2 Professional and it seems to work just fine. Use at your own risk.
When you create a new relationship through Admin -> Studio -> -> Relationships, Sugar create several files at custom folders:
Left Side Hand Relationship (module from which you created the relationship):
custom/Extension/modules/{moduleName}/Ext/Vardefs/{relationshipName}.php
custom/Extension/modules/{moduleName}/Ext/Layoutdefs/{relationshipName}.php
custom/Extension/modules/{moduleName}/Ext/Language/{relationshipName}.php
Right Side Hand Relationship:
custom/Extension/modules/{moduleName}/Ext/Vardefs/{relationshipName}.php
custom/Extension/modules/{moduleName}/Ext/Language/{relationshipName}.php
Relationship itself:
custom/metadata/{relationshipName}Meta.php
Table Dictionary:
custom/Extension/application/Ext/TableDictionary/{relationshipName}.php
Edit custom/application/Ext/TableDictionary/tabledictionary.ext.php file and delete include(‘custom/metadata/{relationshipName}.php’);
To remove the relationship, you need to delete these files. After removing all these files you should need to go to Admin -> Repair -> Quick Repair and Rebuild
Original post:
http://www.sugarcrm.com/forums/showthread.php?t=37781
This plugin displays the icon for all social groups a user belongs to in the postbit.
To Install:
Add this product as you would any other vBulletin product.
Admin -> Plugins & Products -> Manage Products -> Add/Import Product
After it is installed, enable it by going to
Admin -> Settings -> Options -> Redinkdesign – Group Icons in Postbit -> Enable
A live demo can be found at http://www.b15u.com
This code has been updated for vBulletin 4.0. It’s no longer supported for vBulletin 3.x.For the latest version, go here https://github.com/redinkdesign/Social-Group-Icons-in-Postbit
This code is still beta, use at your own risk.
<?php
/**
All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You can view a copy of the GNU General Public Licsense at
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
**/
class redDB {
private $__db_host;
private $__db_username;
private $__db_password;
private $__db_name;
private $__db_handle;
private $__sql;
private $__table_name;
private $__result;
function __construct($host, $username, $password, $db_name, $db_handle = ''){
if (empty($db_handle)){
$this->__db_host = $host;
$this->__db_username = $username;
$this->__db_password = $password;
$this->__db_name = $db_name;
$this->connect();
}else{
$this->__db_handle = $db_handle;
}
}
/**
* Initialize our table object
*
* @example $this->init('users_table');
*
* @param string $table
* @return object
*/
public function init($table = ''){
if(empty($table)){
$this->throw_error(__METHOD__, __LINE__, 'No table name specified.');
}
$this->__table_name = $table;
$ar_fields = $this->get_table_fields();
if (!is_array($ar_fields)) {
$this->throw_error(__METHOD__, __LINE__, "ERROR: Table '{$this->__table_name}' has no fields.");
}
foreach ($ar_fields as $field){
switch ($field->type){
case "INTEGER":
case "TINYINT":
case "SMALLINT":
case "MEDIUMINT":
$this->{$field->name} = 0;
break;
case "NUMERIC":
case "FLOAT":
case "DECIMAL":
$this->{$field->name} = 0.00;
break;
default:
$this->{$field->name} = '';
break;
}
if (!empty($field->def)) {
$this->{$field->name} = $field->def;
}
}
return $this;
}
/**
* Alias for @link init
*
* @param string $table
* @return object
*/
public function init_table($table){
return $this->init($table);
}
/**
* Returns a single record as a table object depending on
* constraint passed in
*
* @example $this->get_single_record("id = 22");
*
* @param string $constraint
* @return object
*/
public function get_single_record($constraint = ''){
if (empty($this->__table_name)){
$this->throw_error(__METHOD__, __LINE__, "You must initialize a table before retrieving a record.");
}
if (empty($constraint)){
$this->throw_error(__METHOD__, __LINE__, "No constraint entered.");
}
$this->__sql = "select top 1 * from {$this->__table_name} where {$constraint}";
return $this->get_single_result();
}
/**
* Alias for @link get_single_record
*
* @param string $constraint
* @return object
*/
public function get($constraint){
return $this->get_single_record($constraint);
}
/**
* Inserts a new record or updates if it already exists
* Use this for quick updates/inserts
*
* For custom updates, use @link update
*
* @return boolean
*/
public function save(){
$duplicate_sql = '';
$this->__sql = "insert into {$this->__table_name} values (";
foreach ($this as $key => $val){
if (substr($key, 0, 2) == '__'){
continue;
}
$this->__sql .= "'{$this->escape($val)}'" . ',';
}
$this->__sql = trim($this->__sql, ',');
$this->__sql .= ")";
return $this->execute_query($this->__sql);
}
public function insert(){
return $this->save();
}
/**
* Updates an existing record depending on custom constraints
* Use this for complex updates instead of @link save
*
* @param string $where_constraint
* @return boolean
*/
public function update($where_constraint = ''){
if (empty($where_constraint)){
$this->throw_error(__METHOD__, __LINE__, 'Missing WHERE constraint. eg. ID = 222');
}
$this->__sql = "update {$this->__table_name} set ";
foreach ($this as $key => $val){
if (substr($key, 0, 2) == '__'){
continue;
}
$this->__sql .= "{$key} = '{$this->escape($val)}'" . ',';
}
$this->__sql = trim($this->__sql, ',');
$this->__sql .= ' where ' . $where_constraint;
return $this->execute_query($this->__sql);
}
/**
* Executes a query
*
* @param string $query
* @return boolean
*/
public function execute_query($query){
$this->__sql = $query;
if(!$this->query($this->__sql)){
$this->throw_error(__METHOD__, __LINE__);
}
return true;
}
/**
* Send out a query and return the first field of the first result row
* eg. select count(*) as count from blah; only the value of count will be returned
*
* @param string $query
* @return string return value of query
*/
public function get_query_value($query){
if (empty($query)) $this->throw_error(__METHOD__, __LINE__, 'Query missing.');
$this->__sql = $query;
$this->__result = $this->query($this->__sql);
if (!$this->__result){
$this->throw_error(__METHOD__, __LINE__);
}
$ar_result = mssql_fetch_array($this->__result);
if (!empty($ar_result[0])){
return $ar_result[0];
}else{
return false;
}
}
/**
* Get data from the initialized table depending on constraint, limit and order
* Returns results in an array of objects
*
* @param string $constraint - optional
* @param string $limit - optional
* @param string $order_by - optional
* @return array of objects
*/
public function get_data($constraint = '', $limit = '', $order_by = ''){
if (empty($this->__table_name)) $this->throw_error(__METHOD__, __LINE__, 'Table missing.');
$this->__sql = "select " . (!empty($limit)? " top {$this->escape($limit)}" : '') . " * from {$this->__table_name}" . (!empty($constraint)? " where {$constraint}" : '') . (!empty($order_by)? " order by {$this->escape($order_by)}" : '');
$this->__result = $this->query($this->__sql);
if (!$this->__result){
$this->throw_error(__METHOD__, __LINE__);
}
$ar_results = array();
while($obj = mssql_fetch_object($this->__result)){
$ar_results[] = $obj;
}
if (is_array($ar_results)){
return $ar_results;
}else{
return false;
}
}
/**
* Runs a query and returns results in an array of objects
*
* @param string $query
* @return array
*/
public function get_query_data($query){
if (empty($query)) $this->throw_error(__METHOD__, __LINE__, "Query missing.");
$this->__sql = $query;
$this->__result = $this->query($this->__sql);
if(!$this->__result){
$this->throw_error(__METHOD__, __LINE__);
}
$ar_results = array();
while ($obj = mssql_fetch_object($this->__result)){
$ar_results[] = $obj;
}
if (is_array($ar_results)){
return $ar_results;
}else{
return false;
}
}
/**
* Escapes special characters in a string for use in a SQL statement
*
* @param string $string
* @return string
*/
public function escape($string){
return str_replace("'", "''", $string);
}
/**
* Gets the sql statement that was executed
*
* @return string
*/
public function get_sql(){
return $this->__sql;
}
/**
* Gets the number of rows in a result
*
* @return int
*/
public function get_num_rows(){
return mssql_num_rows($this->__result);
}
/**
* Gets the number of affected rows in a previous MySQL operation
* Returns an integer greater than zero which indicated the number of rows affected or retrieved.
* Zero indicates that no records where updated for an UPDATE statement,
* no rows matched the WHERE clause in the query or that no query has yet been executed.
* -1 indicates that the query returned an error.
*
* @return int
*/
public function get_affected_rows(){
return mssql_rows_affected($this->__db_handle);
}
private function connect(){
if (!$this->__db_handle = mssql_connect($this->__db_host, $this->__db_username, $this->__db_password)){
$this->throw_error(__METHOD__, __LINE__, 'Could not connect to SQL server.');
}
if (!mssql_select_db($this->__db_name, $this->__db_handle)){
$this->throw_error(__METHOD__, __LINE__, 'Could not select database ' . $this->__db_name);
}
}
private function get_single_result(){
$this->__result = $this->query($this->__sql);
if (!$this->__result){
$this->throw_error(__METHOD__, __LINE__);
}
$ob_record = mssql_fetch_object($this->__result);
if (is_object($ob_record)){
foreach($ob_record as $key => $value){
$this->{$key} = $value;
}
return $this;
}else{
return false;
}
}
private function get_table_fields(){
$this->__sql = "select top 1 * from {$this->escape($this->__table_name)}";
$this->__result = mssql_query($this->__sql, $this->__db_handle);
if (!$this->__result){
$this->throw_error(__METHOD__, __LINE__,'Could not fetch table fields.');
}
for ($i = 0; $i < mssql_num_fields($this->__result); $i++){
$field = mssql_fetch_field($this->__result, $i);
$ar_fields[$field->name]->name = $field->name;
$ar_fields[$field->name]->type = strtoupper($field->type);
$ar_fields[$field->name]->max_length = $field->max_length;
$ar_fields[$field->name]->column_source = $field->column_source;
$ar_fields[$field->name]->numeric = $field->numeric;
}
if (count($ar_fields) > 0){
return $ar_fields;
}else{
$this->throw_error(__METHOD__, __LINE__, "No columns found for table {$this->__table_name}.");
}
}
private function query($query){
$this->__result = mssql_query($query, $this->__db_handle);
return $this->__result;
}
private function throw_error($function_name, $line_number, $error_msg = ''){
die('<font style="color: red; font-weight: bold;">-- Error --</font><br />' . $function_name . ' at line ' . $line_number . '<br />' . (!empty($error_msg)? "<br />Message: $error_msg" : "Invalid Query: {$this->__sql}"));
}
}
?>
All code is Copyright 2009 by Ashwin Surajbali (http://www.redinkdesign.net).
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You can view a copy of the GNU General Public Licsense at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
“Most people getting started with JavaScript these days are faced with the challenging task of picking a library to use, or at least which one to learn first. If you’re working for a company chances are they have already chosen a framework for you, in which case the point is somewhat moot. If this is the case and they’ve chosen MooTools and you’re used to jQuery, then this article might still be of some use to you. ”
Written by Aaron Newton
Article here:
http://jqueryvsmootools.com/
This is a quick and dirty screen scraper for quantcast.com. It currently only grabs the site rank and description.
Updated: 8/10/2010
Rank, Description and US Stats are now working again. Global Stats are no longer available.
Usage:
$q = new QuantCast('cnet.com');
echo '<strong>Rank:</strong> ' . $q->getRank() . '<br />';
echo '<strong>Desc:</strong> ' . $q->getDescription() . '<br />';
Class Source Code:
class QuantCast {
public $siteName;
public $rank = 0;
public $description = '';
public $usTraffic = '';
private $siteContents;
public function __construct($siteName){
$this->siteName = strtolower(str_replace('http://', '', $siteName));
$url = "http://www.quantcast.com/{$this->siteName}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729)");
$this->siteContents = curl_exec($ch);
curl_close($ch);
$newlines = array("t","n","r","x20x20","\0","x0B");
$this->siteContents = str_replace($newlines, "", html_entity_decode($this->siteContents));
}
public function getRank(){
$this->_getRank();
return $this->rank;
}
public function getDescription(){
$this->_getDescription();
return $this->description;
}
public function getUsStats(){
$this->_getUsStats();
return $this->usTraffic;
}
private function _getRank(){
$start = strpos($this->siteContents, '<li>');
$end = strpos($this->siteContents, '</li>', $start);
$data = substr($this->siteContents, $start, $end-$start);
preg_match_all('/<strong>([0-9,]*)</strong>/', $data, $ar_matches);
$this->rank = $ar_matches[1][0];
}
private function _getDescription(){
$start = strpos($this->siteContents, '<div>');
$end = strpos($this->siteContents, '</div>', $start);
$data = substr($this->siteContents, $start, $end-$start);
$this->description = strip_tags($data);
}
private function _getUsStats(){
$site = explode('.', $this->siteName);
$td = '<td id="reach-wd:' . $site[1] . '.' . $site[0] . '">';
$start = strpos($this->siteContents, $td);
$end = strpos($this->siteContents, '</td>', $start);
$data = substr($this->siteContents, $start, $end-$start);
$data = strip_tags($data);
$data = str_replace('Est.MonthlyUS People', '', $data);
$this->usTraffic = $data;
}
}
Recent Comments