예제 #1
0
 public function __get($key)
 {
     $fielddefs = news_ops::get_fielddefs(FALSE);
     switch ($key) {
         case 'alias':
             $alias = munge_string_to_url($this->name);
             return $alias;
         case 'id':
         case 'name':
         case 'type':
         case 'max_length':
         case 'create_date':
         case 'modified_date':
         case 'item_order':
         case 'public':
         case 'value':
             if (isset($this->_data[$key])) {
                 return $this->_data[$key];
             }
             break;
         case 'extra':
             if (isset($this->_data['extra'])) {
                 if (!is_array($this->_data['extra'])) {
                     $this->_data['extra'] = unserialize($this->_data['extra']);
                 }
                 return $this->_data['extra'];
             }
             break;
         case 'options':
             $extra = $this->extra;
             if (is_array($extra) && isset($extra['options'])) {
                 return $extra['options'];
             }
             break;
         case 'displayvalue':
             if (!$this->_displayvalue) {
                 if (isset($this->_data['value'])) {
                     $value = $this->_data['value'];
                     $this->_displayvalue = $value;
                     if ($this->type == 'dropdown') {
                         // dropdowns may have a different displayvalue than actual value.
                         if (is_array($this->options) && isset($this->options[$value])) {
                             $this->_displayvalue = $this->options[$value];
                         }
                     }
                 }
             }
             return $this->_displayvalue;
             break;
         case 'fielddef_id':
             return $this->_data['id'];
     }
 }
예제 #2
0
$smarty->assign('itemcount', count($entryarray));
$smarty->assign_by_ref('items', $entryarray);
$smarty->assign('category_label', $this->Lang('category_label'));
$smarty->assign('author_label', $this->Lang('author_label'));
foreach ($params as $key => $value) {
    if ($key == 'mact' || $key == 'action') {
        continue;
    }
    $smarty->assign('param_' . $key, $value);
}
$catName = '';
if (isset($params['category'])) {
    $catName = $params['category'];
} else {
    if (isset($params['category_id'])) {
        $catName = $db->GetOne('SELECT news_category_name FROM ' . cms_db_prefix() . 'module_news_categories where news_category_id=?', array($params['category_id']));
    }
}
$smarty->assign('category_name', $catName);
unset($params['pagenumber']);
$items = news_ops::get_categories($id, $params, $returnid);
$smarty->assign('count', count($items));
$smarty->assign('cats', $items);
#Display template
echo "<!-- Displaying News Module -->\n";
$template = 'summary' . $this->GetPreference('current_summary_template');
if (isset($params['summarytemplate'])) {
    $template = 'summary' . $params['summarytemplate'];
}
echo $this->ProcessTemplateFromDatabase($template);
# vim:ts=4 sw=4 noet
예제 #3
0
 public static function preloadFieldData($ids)
 {
     if (!is_array($ids) && is_numeric($ids)) {
         $ids = array($ids);
     }
     $tmp = array();
     for ($i = 0; $i < count($ids); $i++) {
         $n = (int) $ids[$i];
         if ($n < 0) {
             continue;
         }
         if (is_array(self::$_cached_fieldvals) && isset(self::$_cached_fieldvals[$n])) {
             continue;
         }
         $tmp[] = $n;
     }
     if (!is_array($tmp) || !count($tmp)) {
         return;
     }
     sort($tmp);
     $idlist = array_unique($tmp);
     $fielddefs = self::get_fielddefs();
     if (!count($fielddefs)) {
         return;
     }
     $db = cmsms()->GetDb();
     $query = 'SELECT A.news_id,A.fielddef_id,A.value FROM ' . cms_db_prefix() . 'module_news_fieldvals A
           INNER JOIN ' . cms_db_prefix() . 'module_news_fielddefs B
           ON A.fielddef_id = B.id
           WHERE news_id IN (' . implode(',', $idlist) . ') 
           ORDER BY A.news_id,B.item_order';
     $dbr = $db->GetArray($query);
     if (!$dbr) {
         return;
     }
     // initialization.
     if (!is_array(self::$_cached_fieldvals)) {
         self::$_cached_fieldvals = array();
     }
     foreach ($idlist as $news_id) {
         if (isset(self::$_cached_fieldvals[$news_id])) {
             continue;
         }
         self::$_cached_fieldvals[$news_id] = array();
         foreach ($fielddefs as $field) {
             $obj = new news_field();
             foreach ($field as $k => $v) {
                 $obj->{$k} = $v;
             }
             self::$_cached_fieldvals[$news_id][$field['id']] = $obj;
         }
     }
     // fill with values.
     foreach ($dbr as $row) {
         $news_id = $row['news_id'];
         $flddef_id = $row['fielddef_id'];
         $value = $row['value'];
         if (!isset(self::$_cached_fieldvals[$news_id][$flddef_id])) {
             continue;
         }
         self::$_cached_fieldvals[$news_id][$flddef_id]->value = $value;
     }
 }
예제 #4
0
                $preview = TRUE;
            }
        }
    }
}
if ($preview || !$smarty->isCached($this->GetDatabaseResource($template), $cache_id, $compile_id)) {
    // not cached... have to do to the work.
    if (isset($params['articleid']) && $params['articleid'] == -1) {
        $article = news_ops::get_latest_article();
    } else {
        if (isset($params['articleid']) && (int) $params['articleid'] > 0) {
            $show_expired = $this->GetPreference('expired_viewable', 1);
            if (isset($params['showall'])) {
                $show_expired = 1;
            }
            $article = news_ops::get_article_by_id((int) $params['articleid'], TRUE, $show_expired);
        }
    }
    if (!$article) {
        throw new CmsError404Exception('Article ' . (int) $params['articleid'] . ' not found, or otherwise unavailable');
        return;
    }
    $article->set_linkdata($id, $params);
    $return_url = $this->CreateReturnLink($id, isset($params['origid']) ? $params['origid'] : $returnid, $this->lang('news_return'));
    $smarty->assign_by_ref('return_url', $return_url);
    $smarty->assign_by_ref('entry', $article);
    $catName = '';
    if (isset($params['category_id'])) {
        $catName = $db->GetOne('SELECT news_category_name FROM ' . cms_db_prefix() . 'module_news_categories where news_category_id=?', array($params['category_id']));
    }
    $smarty->assign('category_name', $catName);
    if ($this->CheckPermission('Modify News')) {
        $onerow->editlink = $this->CreateLink($id, 'editarticle', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('edit'), '', '', 'systemicon'), array('articleid' => $row['news_id']));
    }
    if ($this->CheckPermission('Delete News')) {
        $onerow->deletelink = $this->CreateLink($id, 'deletearticle', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('delete'), '', '', 'systemicon'), array('articleid' => $row['news_id']), $this->Lang('areyousure'));
    }
    $entryarray[] = $onerow;
    $rowclass == "row1" ? $rowclass = "row2" : ($rowclass = "row1");
}
$smarty->assign_by_ref('items', $entryarray);
$smarty->assign('itemcount', count($entryarray));
$smarty->assign('addlink', $this->CreateLink($id, 'addarticle', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newobject.gif', $this->Lang('addarticle'), '', '', 'systemicon'), array(), '', false, false, '') . ' ' . $this->CreateLink($id, 'addarticle', $returnid, $this->Lang('addarticle'), array(), '', false, false, 'class="pageoptions"'));
$smarty->assign('form2start', $this->CreateFormStart($id, 'defaultadmin', $returnid));
$smarty->assign('form2end', $this->CreateFormEnd());
$smarty->assign('submit_reassign', $this->CreateInputSubmit($id, 'submit_reassign', $this->Lang('submit')));
$categorylist = news_ops::get_category_list();
$smarty->assign('categoryinput', $this->CreateInputDropdown($id, 'category', $categorylist));
if ($this->CheckPermission('Delete News')) {
    $smarty->assign('submit_massdelete', $this->CreateInputSubmit($id, 'submit_massdelete', $this->Lang('delete_selected'), '', '', $this->Lang('areyousure_deletemultiple')));
}
$smarty->assign('reassigntext', $this->Lang('reassign_category'));
$smarty->assign('selecttext', $this->Lang('select'));
$smarty->assign('filtertext', $this->Lang('title_filter'));
$smarty->assign('statustext', $this->Lang('status'));
$smarty->assign('startdatetext', $this->Lang('startdate'));
$smarty->assign('enddatetext', $this->Lang('enddate'));
$smarty->assign('statetext', $this->Lang('state'));
$smarty->assign('titletext', $this->Lang('title'));
$smarty->assign('postdatetext', $this->Lang('postdate'));
$smarty->assign('categorytext', $this->Lang('category'));
$gCms = cmsms();
예제 #6
0
 public static function get_fielddefs($publiconly = TRUE)
 {
     if (!is_array(self::$_cached_fielddefs)) {
         $db = cmsms()->GetDb();
         $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_news_fielddefs WHERE public = 1 ORDER BY item_order';
         if (!$publiconly) {
             $query = 'SELECT * FROM ' . cms_db_prefix() . 'module_news_fielddefs ORDER BY item_order';
         }
         $tmp = $db->GetArray($query);
         self::$_cached_fielddefs = array();
         if (is_array($tmp) && count($tmp)) {
             for ($i = 0; $i < count($tmp); $i++) {
                 self::$_cached_fielddefs[$tmp[$i]['id']] = $tmp[$i];
             }
         }
     }
     return self::$_cached_fielddefs;
 }
예제 #7
0
            $data = unserialize(file_get_contents($fname));
            if (is_array($data)) {
                // get passed data into a standard format.
                $article = new news_article();
                $article->set_linkdata($id, $params);
                news_ops::fill_article_from_formparams($article, $data, FALSE, FALSE);
            }
        }
    }
} else {
    if (isset($params['articleid']) && $params['articleid'] == -1) {
        $article = news_ops::get_latest_article();
        $article->set_linkdata($id, $params);
    } else {
        if (isset($params['articleid']) && (int) $params['articleid'] > 0) {
            $article = news_ops::get_article_by_id((int) $params['articleid']);
            $article->set_linkdata($id, $params);
            // todo, should we 404 here if article not found?
        }
    }
}
if (!$article) {
    return;
}
$return_url = $this->CreateReturnLink($id, isset($params['origid']) ? $params['origid'] : $returnid, $this->lang('news_return'));
$smarty->assign_by_ref('return_url', $return_url);
$smarty->assign_by_ref('entry', $article);
$catName = '';
if (isset($params['category_id'])) {
    $catName = $db->GetOne('SELECT news_category_name FROM ' . cms_db_prefix() . 'module_news_categories where news_category_id=?', array($params['category_id']));
}
예제 #8
0
 public function __get($key)
 {
     switch ($key) {
         case 'id':
         case 'author_id':
         case 'title':
         case 'content':
         case 'summary':
         case 'extra':
         case 'news_url':
         case 'postdate':
             // db time format
         // db time format
         case 'startdate':
             // db time format
         // db time format
         case 'enddate':
             // db time format
         // db time format
         case 'create_date':
             // db time format
         // db time format
         case 'modified_date':
             // db time format
         // db time format
         case 'category_id':
         case 'status':
             return $this->_getdata($key);
         case 'file_location':
             $config = cmsms()->GetConfig();
             $url = $config['uploads_url'] . '/news/id' . $this->id;
             return $url;
         case 'author':
             // metadata.
             return $this->_getauthorinfo($this->author_id);
         case 'authorname':
             // metadata.
             return $this->_getauthorinfo($this->author_id, TRUE);
         case 'category':
             // metadata.
             return news_ops::get_category_name_from_id($this->category_id);
         case 'useexp':
             if (isset($this->_meta['useexp'])) {
                 return $this->_meta['useexp'];
             }
             return 0;
         case 'canonical':
             // metadata
             return $this->_get_canonical();
             break;
         case 'fields':
         case 'customfieldsbyname':
             // deprecated
         // deprecated
         case 'fieldsbyname':
             // deprecated
             if (isset($this->_rawdata['fieldsbyname'])) {
                 return $this->_rawdata['fieldsbyname'];
             }
             break;
             //       case 'printlink':    // meta
             // 	// metadata
             // 	return $this->_get_printurl(true);
             //       case 'printurl':    // meta
             // 	// metadata
             // 	return $this->_get_printurl();
         //       case 'printlink':    // meta
         // 	// metadata
         // 	return $this->_get_printurl(true);
         //       case 'printurl':    // meta
         // 	// metadata
         // 	return $this->_get_printurl();
         case 'returnid':
             // metadata
             return $this->_get_returnid();
         case 'params':
             // metadata
             return $this->_get_params();
         default:
             // check if there is a field with this alias
             if (isset($this->_rawdata['fieldsbyname']) && is_array($this->_rawdata['fieldsbyname'])) {
                 foreach ($this->_rawdata['fieldsbyname'] as $fname => &$obj) {
                     if (!is_object($obj)) {
                         continue;
                     }
                     if ($key == $obj->alias) {
                         return $obj->value;
                     }
                 }
             }
             //throw new Exception('Requesting indvlid data from News article object '.$key);
     }
 }