1: <?php
2:
3: /**
4: * Description of Title
5: *
6: * @author SARTAJ
7: */
8:
9: namespace Sphp\Comp\Html {
10:
11: class Title extends \Sphp\tools\Component {
12: private $blnautoseo = false;
13: private static $blnrender = false;
14:
15: public function fu_autoSEO() {
16: $this->blnautoseo = true;
17: }
18: public function fu_setMetaKeywords($v) {
19: $this->setAttribute("metakeywords", $v);
20: }
21: public function fu_setMetaDescription($v) {
22: $this->setAttribute("metadescription", $v);
23: }
24: public function fu_setMetaClassification($v) {
25: $this->setAttribute("metaclassification", $v);
26: }
27: public function fu_setKeywords($v) {
28: $this->setAttribute("keywords", $v);
29: }
30: private function autoSEO1($ar1) {
31: foreach ($ar1 as $t1){
32: if($t1->myclass == "Sphp\\tools\\NodeTag"){
33: $this->optimizeTags($t1);
34: if($t1->hasChildren()){
35: $this->autoSEO1($t1->getChildren());
36: }
37: }
38: }
39: }
40: private function optimizeTags($element) {
41: switch($element->tagName){
42: case 'a':{
43: if(! $element->hasAttribute('title')) $element->setAttribute('title', \SphpBase::sphp_settings()->getKeyword());
44: break;
45: }
46: case 'img':{
47: if(! $element->hasAttribute('title')) $element->setAttribute('title', \SphpBase::sphp_settings()->getKeyword());
48: if(! $element->hasAttribute('alt')) $element->setAttribute('alt', \SphpBase::sphp_settings()->getKeyword());
49: break;
50: }
51: }
52: }
53: protected function onrender() {
54: global $cmpname;
55: // force render once
56: if(! self::$blnrender){
57: self::$blnrender = true;
58: $this->fu_unsetRenderTag();
59: $hh1 = $this->getInnerHTML();
60: $hh1 = $this->executePHPCode($hh1);
61: // 70 characters
62: \SphpBase::sphp_settings()->title = $hh1;
63: if ($this->element->hasAttribute("metakeywords")) {
64: \SphpBase::sphp_settings()->metakeywords = $this->getAttribute("metakeywords");
65: } else {
66: \SphpBase::sphp_settings()->metakeywords = $hh1;
67: }
68: // length = 150
69: if ($this->element->hasAttribute("metadescription")) {
70: \SphpBase::sphp_settings()->metadescription = $this->getAttribute("metadescription");
71: } else {
72: \SphpBase::sphp_settings()->metadescription = $hh1;
73: }
74: if ($this->element->hasAttribute("metaclassification")) {
75: \SphpBase::sphp_settings()->metaclassification = $this->getAttribute("metaclassification");
76: } else {
77: \SphpBase::sphp_settings()->metaclassification = $hh1;
78: }
79: if ($this->element->hasAttribute("metaauthor")) {
80: \SphpBase::sphp_settings()->metaauthor = $this->getAttribute("metaauthor");
81: } else {
82: \SphpBase::sphp_settings()->metaauthor = $cmpname;
83: }
84: if ($this->element->hasAttribute("keywords")) {
85: \SphpBase::sphp_settings()->keywords = explode(",", $this->getAttribute("keywords"));
86: } else {
87: \SphpBase::sphp_settings()->keywords = explode(",",\SphpBase::sphp_settings()->metakeywords);
88: }
89: // create social media og meta tags for sharing webpage
90: $str1 = '<link rel="canonical" href="'. getThisGateURL() .'" /><meta property="og:locale" content="en_US" />
91: <meta property="og:site_name" content="'. $cmpname .'" />
92: <meta property="og:type" content="website" />
93: <meta property="og:title" content="'. \SphpBase::sphp_settings()->title .'" />
94: <meta property="og:description" content="'. \SphpBase::sphp_settings()->metadescription .'" />
95: <meta property="og:url" content="'. getThisGateURL() .'" />';
96: if ($this->element->hasAttribute("img")) {
97: $str1 .= '<meta property="og:image" content="'. $this->element->getAttribute("img") .'" />';
98: }else{
99: $str1 .= '<meta property="og:image" content="'. \SphpBase::sphp_settings()->slib_res_path .'/masters/default/imgs/android-icon-192x192.png" />';
100: }
101: $str1 .= '<meta property="og:image:width" content="600" />
102: <meta property="og:image:height" content="600" />';
103: // fb meta tags
104: if ($this->element->hasAttribute("fb-admin")) {
105: $this->element->setDefaultAttribute('article-time', '2019-01-22T11:10:05+00:00');
106: $this->element->setDefaultAttribute('article-time-modified', '2020-01-22T11:10:05+00:00');
107: $this->element->setDefaultAttribute('article-publisher', 'https://www.facebook.com/ITKruze/');
108: $str1 .= '<meta property="fb:admins" content="'. $this->element->getAttribute("fb-admin") .'" />
109: <meta property="article:published_time" content="'. $this->element->getAttribute("article-time") .'" />
110: <meta property="article:modified_time" content="'. $this->element->getAttribute("article-time-modified") .'" />
111: <meta property="article:publisher" content="'. $this->element->getAttribute("article-publisher") .'" />';
112: }
113: // twiter tags
114: if ($this->element->hasAttribute("twitter-site")) {
115: $this->element->setDefaultAttribute('twitter-image', \SphpBase::sphp_settings()->slib_res_path .'/masters/default/imgs/android-icon-192x192.png');
116: $str1 .= '<meta name="twitter:card" content="summary_large_image" /><meta property="twitter:site" content="'. $this->element->getAttribute("twitter-site") .'" />
117: <meta property=""twitter:title" content="'. \SphpBase::sphp_settings()->title .'" />
118: <meta property="twitter:description" content="'. \SphpBase::sphp_settings()->metadescription .'" />
119: <meta property="twitter:image" content="'. $this->element->getAttribute("twitter-image") .'" />';
120: }
121:
122: addFileLinkCode('ogtag',$str1);
123: $this->setInnerHTML('');
124: if($this->blnautoseo){
125: // component temp file
126: $dom = $this->frontobj->HTMLParser->dhtmldom;
127: $this->autoSEO1($dom->root->getChildren());
128: }
129: }else{ // render child temp file
130: if($this->blnautoseo){
131: // element temp file object because component is same in both file
132: $dom = $this->element->frontobj->HTMLParser->dhtmldom;
133: $this->autoSEO1($dom->root->getChildren());
134: }
135: }
136: }
137:
138: }
139:
140: }
141: